Dear all,
the motivation for the following is rbmj's patch for libstdc++ on VxWorks,
cf. http://gcc.gnu.org/ml/gcc-patches/2012-05/msg00073.html
Note that gfortan is used on VxWorks as the following email proves:
http://gcc.gnu.org/ml/fortran/2012-02/msg00115.html
(VxWorks is a real-time embedded operating system:
https://en.wikipedia.org/wiki/VxWorks)
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?)
Tobias
[1] http://pubs.opengroup.org/onlinepubs/000095399/functions/open.html
[2]
http://www-kryo.desy.de/documents/vxWorks/V5.5/vxworks/ref/ioLib.html#open
2012-05-15 Tobias Burnus <bur...@net-b.de>
* io/unix.c (fallback_access): Pass mode to "open" on
VxWorks.
(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)
+#else
if ((mode & R_OK) && (fd = open (path, O_RDONLY)) < 0)
+#endif
return -1;
close (fd);
+#ifdef __VXWORKS__
+ if ((mode & W_OK) && (fd = open (path, O_WRONLY, 0666)) < 0)
+#else
if ((mode & W_OK) && (fd = open (path, O_WRONLY)) < 0)
+#endif
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);
+ S_IRUSR | S_IWUSR, 0600);
#else
- 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);
#endif
}
while (fd == -1 && errno == EEXIST);