diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2010-08-01 14:22:18 +0300 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2010-08-01 14:22:18 +0300 |
commit | 47dad3ff97135ef8a26e0ecbc2170fba6c4e89be (patch) | |
tree | 9d55d4053f91dc21cfcd5a77b3e7e616eeaa2059 /libgfortran/io | |
parent | 22db1fbca9fb5ec31b41180a8696ed5fef081c19 (diff) | |
download | gcc-47dad3ff97135ef8a26e0ecbc2170fba6c4e89be.zip gcc-47dad3ff97135ef8a26e0ecbc2170fba6c4e89be.tar.gz gcc-47dad3ff97135ef8a26e0ecbc2170fba6c4e89be.tar.bz2 |
Use access(2) instead of stat(2) to test file existence.
From-SVN: r162798
Diffstat (limited to 'libgfortran/io')
-rw-r--r-- | libgfortran/io/unix.c | 76 |
1 files changed, 41 insertions, 35 deletions
diff --git a/libgfortran/io/unix.c b/libgfortran/io/unix.c index eea03ba..a2903af 100644 --- a/libgfortran/io/unix.c +++ b/libgfortran/io/unix.c @@ -131,6 +131,46 @@ typedef struct stat gfstat_t; #endif +#ifndef HAVE_ACCESS + +#ifndef W_OK +#define W_OK 2 +#endif + +#ifndef R_OK +#define R_OK 4 +#endif + +#ifndef F_OK +#define F_OK 0 +#endif + +/* Fallback implementation of access() on systems that don't have it. + Only modes R_OK, W_OK and F_OK are used in this file. */ + +static int +fallback_access (const char *path, int mode) +{ + if ((mode & R_OK) && open (path, O_RDONLY) < 0) + return -1; + + if ((mode & W_OK) && open (path, O_WRONLY) < 0) + return -1; + + if (mode == F_OK) + { + gfstat_t st; + return stat (path, &st); + } + + return 0; +} + +#undef access +#define access fallback_access +#endif + + /* Unix and internal stream I/O module */ static const int BUFFER_SIZE = 8192; @@ -1580,15 +1620,11 @@ int file_exists (const char *file, gfc_charlen_type file_len) { char path[PATH_MAX + 1]; - gfstat_t statbuf; if (unpack_filename (path, file, file_len)) return 0; - if (stat (path, &statbuf) < 0) - return 0; - - return 1; + return !(access (path, F_OK)); } @@ -1695,36 +1731,6 @@ inquire_unformatted (const char *string, int len) } -#ifndef HAVE_ACCESS - -#ifndef W_OK -#define W_OK 2 -#endif - -#ifndef R_OK -#define R_OK 4 -#endif - -/* Fallback implementation of access() on systems that don't have it. - Only modes R_OK and W_OK are used in this file. */ - -static int -fallback_access (const char *path, int mode) -{ - if ((mode & R_OK) && open (path, O_RDONLY) < 0) - return -1; - - if ((mode & W_OK) && open (path, O_WRONLY) < 0) - return -1; - - return 0; -} - -#undef access -#define access fallback_access -#endif - - /* inquire_access()-- Given a fortran string, determine if the file is * suitable for access. */ |