Don't assume File-I/O mode bits match the host's format

inf_child_fileio_open and its gdbserver equivalent both assume that
the mode_t bits defined in gdb/fileio.h are the same as those used
by the open system call, but there is no mechanism to ensure this is
the case.  This commit adds a conversion function to handle systems
where the File-I/O definitions do not align with the host's.

gdb/ChangeLog:

	* common/fileio.h (fileio_to_host_mode): New declaration.
	* common/fileio.c (fileio_to_host_mode): New Function.
	* inf-child.c (inf_child_fileio_open): Process mode argument
	with fileio_to_host_mode.

gdb/gdbserver/ChangeLog:

	* hostio.c (handle_open): Process mode argument with
	fileio_to_host_mode.
This commit is contained in:
Gary Benson 2015-06-09 10:00:15 +01:00
parent ecef18c564
commit 3ac2e371a1
6 changed files with 75 additions and 7 deletions

View file

@ -109,6 +109,55 @@ fileio_to_host_openflags (int fileio_open_flags, int *open_flags_p)
return 0;
}
/* See fileio.h. */
int
fileio_to_host_mode (int fileio_mode, mode_t *mode_p)
{
mode_t mode = 0;
if (fileio_mode & ~FILEIO_S_SUPPORTED)
return -1;
if (fileio_mode & FILEIO_S_IFREG)
mode |= S_IFREG;
if (fileio_mode & FILEIO_S_IFDIR)
mode |= S_IFDIR;
if (fileio_mode & FILEIO_S_IFCHR)
mode |= S_IFCHR;
if (fileio_mode & FILEIO_S_IRUSR)
mode |= S_IRUSR;
if (fileio_mode & FILEIO_S_IWUSR)
mode |= S_IWUSR;
if (fileio_mode & FILEIO_S_IXUSR)
mode |= S_IXUSR;
#ifdef S_IRGRP
if (fileio_mode & FILEIO_S_IRGRP)
mode |= S_IRGRP;
#endif
#ifdef S_IWGRP
if (fileio_mode & FILEIO_S_IWGRP)
mode |= S_IWGRP;
#endif
#ifdef S_IXGRP
if (fileio_mode & FILEIO_S_IXGRP)
mode |= S_IXGRP;
#endif
if (fileio_mode & FILEIO_S_IROTH)
mode |= S_IROTH;
#ifdef S_IWOTH
if (fileio_mode & FILEIO_S_IWOTH)
mode |= S_IWOTH;
#endif
#ifdef S_IXOTH
if (fileio_mode & FILEIO_S_IXOTH)
mode |= S_IXOTH;
#endif
*mode_p = mode;
return 0;
}
/* Convert a host-format mode_t into a bitmask of File-I/O flags. */
static LONGEST