This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, libgfortran] Pass mode in "open" for O_CREAT and on VxWorks

Dear all,

the motivation for the following is rbmj's patch for libstdc++ on VxWorks,

Note that gfortan is used on VxWorks as the following email proves:
(VxWorks is a real-time embedded operating system:

Seemingly, VxWorks differs from POSIX. POSIX [1] has int open(const char *path, int oflag, ... ); and requires only with O_CREAT as third argument at mode_t. By contrast, VxWorks has the following prototype [2] int open (const char * name, int flags, int mode) where "mode" is not optional and the function is not variadic.

This patch does now always passes a mode on VxWorks; I assume that the mode
is ignored if there is no O_CREAT. That part of the code gets only accessed if there is no "access" function; looking at [2], that seems to be the case for VxWorks.

Additionally, in the fall-back implementation of "mkstemp", "open" with O_CREAT is used but no mode has been passed. I added 0600 unconditionally.

The patch was build on x86-64-linux, but I only expect an effect on VxWorks and on systems without mkstemp. OK for the trunk? (Is there a need for backporting?)


2012-05-15  Tobias Burnus  <>

	* io/unix.c (fallback_access): Pass mode to "open" on
	(tempfile_open): Pass mode to "open" for O_CREAT

diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c
index c81163f..b5dca8e 100644
--- a/libgfortran/io/unix.c
+++ b/libgfortran/io/unix.c
@@ -154,11 +154,21 @@ fallback_access (const char *path, int mode)
   int fd;
+  /* Note that POSIX only requires the mode argument with O_CREAT
+     and "open" is variadic while vxWorks always requires the argument.  */
+#ifdef __VXWORKS__
+  if ((mode & R_OK) && (fd = open (path, O_RDONLY, 0666)) < 0)
   if ((mode & R_OK) && (fd = open (path, O_RDONLY)) < 0)
     return -1;
   close (fd);
+#ifdef __VXWORKS__
+  if ((mode & W_OK) && (fd = open (path, O_WRONLY, 0666)) < 0)
   if ((mode & W_OK) && (fd = open (path, O_WRONLY)) < 0)
     return -1;
   close (fd);
@@ -1099,9 +1109,9 @@ tempfile_open (const char *tempdir, char **fname)
 #if defined(HAVE_CRLF) && defined(O_BINARY)
       fd = open (template, O_RDWR | O_CREAT | O_EXCL | O_BINARY,
+		 S_IRUSR | S_IWUSR, 0600);
-      fd = open (template, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+      fd = open (template, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR, 0600);
   while (fd == -1 && errno == EEXIST);

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]