X-Git-Url: https://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ffstatat.c;h=44e326683513bef89bde904575b787d7e0fb910a;hb=dc555c6b2a03b1ee7daa62b3dca1defc4a8bb749;hp=a904e43262c1243c17148d556651618e649730dc;hpb=6cf1a9531a2d12c913b14c1caf1d986c5cf034a2;p=gnulib.git diff --git a/lib/fstatat.c b/lib/fstatat.c index a904e4326..44e326683 100644 --- a/lib/fstatat.c +++ b/lib/fstatat.c @@ -1,6 +1,6 @@ /* Work around an fstatat bug on Solaris 9. - Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc. + Copyright (C) 2006, 2009-2014 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,28 +29,36 @@ #undef __need_system_sys_stat_h #if HAVE_FSTATAT -static inline int +static int orig_fstatat (int fd, char const *filename, struct stat *buf, int flags) { return fstatat (fd, filename, buf, flags); } #endif -#include +/* Write "sys/stat.h" here, not , otherwise OSF/1 5.1 DTK cc + eliminates this include because of the preliminary #include + above. */ +#include "sys/stat.h" #include #include #include -#if HAVE_FSTATAT +#if HAVE_FSTATAT && HAVE_WORKING_FSTATAT_ZERO_FLAG -# undef fstatat +# 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) @@ -58,7 +66,7 @@ rpl_fstatat (int fd, char const *file, struct stat *st, int flag) int result = 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) @@ -71,7 +79,7 @@ rpl_fstatat (int fd, char const *file, struct stat *st, int flag) errno = ENOTDIR; return -1; } - result = fstatat (fd, file, st, flag & ~AT_SYMLINK_NOFOLLOW); + result = orig_fstatat (fd, file, st, flag & ~AT_SYMLINK_NOFOLLOW); } /* Fix stat behavior. */ if (result == 0 && !S_ISDIR (st->st_mode) && file[len - 1] == '/') @@ -82,20 +90,20 @@ rpl_fstatat (int fd, char const *file, struct stat *st, int flag) return result; } -#else /* !HAVE_FSTATAT */ +#else /* ! (HAVE_FSTATAT && HAVE_WORKING_FSTATAT_ZERO_FLAG) */ -/* On mingw, the gnulib defines `stat' as a function-like +/* On mingw, the gnulib defines 'stat' as a function-like macro; but using it in AT_FUNC_F2 causes compilation failure because the preprocessor sees a use of a macro that requires two arguments but is only given one. Hence, we need an inline forwarder to get past the preprocessor. */ -static inline int +static int stat_func (char const *name, struct stat *st) { return stat (name, st); } -/* Likewise, if there is no native `lstat', then the gnulib +/* Likewise, if there is no native 'lstat', then the gnulib defined it as stat, which also needs adjustment. */ # if !HAVE_LSTAT # undef lstat