Mercurial > hg > octave-lojdl > gnulib-hg
diff lib/fstatat.c @ 15564:17091e26f407
openat: test for fstatat (AT_FDCWD, ..., 0) bug
This tests for another fstatat bug on AIX 7.1:
fstatat (AT_FDCWD, ..., 0) does not work. See
<http://lists.gnu.org/archive/html/bug-tar/2011-09/msg00015.html>.
* lib/fstatat.c (FSTATAT_AT_FDCWD_0_BROKEN)
(LSTAT_FOLLOWS_SLASHED_SYMLINK): Default to 0.
(rpl_fstatat): Adjust so that it works around either (or both)
bugs if present.
* m4/openat.m4 (gl_FUNC_FSTATAT): Test for this fstatat bug.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Sat, 03 Sep 2011 10:03:22 -0700 (2011-09-03) |
parents | 2f8afdd5ebf5 |
children | f888e5e48e69 |
line wrap: on
line diff
--- a/lib/fstatat.c +++ b/lib/fstatat.c @@ -46,19 +46,33 @@ # undef fstatat +# ifndef FSTATAT_AT_FDCWD_0_BROKEN +# define FSTATAT_AT_FDCWD_0_BROKEN 0 +# endif + +# ifndef LSTAT_FOLLOWS_SLASHED_SYMLINK +# define LSTAT_FOLLOWS_SLASHED_SYMLINK 0 +# endif + /* fstatat should always follow symbolic links that end in /, but on Solaris 9 it doesn't if AT_SYMLINK_NOFOLLOW is specified. Likewise, trailing slash on a non-directory should be an error. These are the same problems that lstat.c and stat.c address, so - solve it in a similar way. */ + solve it in a similar way. + + AIX 7.1 fstatat (AT_FDCWD, ..., 0) always fails, which is a bug. + Work around this bug if FSTATAT_AT_FDCWD_0_BROKEN is nonzero. */ int rpl_fstatat (int fd, char const *file, struct stat *st, int flag) { - int result = orig_fstatat (fd, file, st, flag); + int result = + (FSTATAT_AT_FDCWD_0_BROKEN && fd == AT_FDCWD && flag == 0 + ? stat (file, st) + : orig_fstatat (fd, file, st, flag)); size_t len; - if (result != 0) + if (LSTAT_FOLLOWS_SLASHED_SYMLINK || result != 0) return result; len = strlen (file); if (flag & AT_SYMLINK_NOFOLLOW)