X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Ffstatat.c;h=326ce215a7bbcc6bb8ab92e92bd6955b3daedecf;hb=4596125141aeea905bd7ed1a8768f11db7402e41;hp=b217126beb11f677d6fa981bda014b6889c92588;hpb=c6d98d8cd52c163c2dba42a41da25356c4dad9f0;p=gnulib.git diff --git a/lib/fstatat.c b/lib/fstatat.c index b217126be..326ce215a 100644 --- a/lib/fstatat.c +++ b/lib/fstatat.c @@ -17,31 +17,53 @@ /* Written by Paul Eggert and Jim Meyering. */ +/* If the user's config.h happens to include , let it include only + the system's here, so that orig_fstatat doesn't recurse to + rpl_fstatat. */ +#define __need_system_sys_stat_h #include +/* Get the original definition of fstatat. It might be defined as a macro. */ +#include +#include +#undef __need_system_sys_stat_h + +#if HAVE_FSTATAT +static inline int +orig_fstatat (int fd, char const *filename, struct stat *buf, int flags) +{ + return fstatat (fd, filename, buf, flags); +} +#endif + #include #include #include #include -#if HAVE_FSTATAT && ! FSTATAT_ST_SIZE_ETC_BROKEN +#if HAVE_FSTATAT && !FSTATAT_ZERO_FLAG_BROKEN -# 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) { - int result = fstatat (fd, file, st, 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) @@ -54,7 +76,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] == '/') @@ -65,12 +87,7 @@ rpl_fstatat (int fd, char const *file, struct stat *st, int flag) return result; } -#else /* ! (HAVE_FSTATAT && ! FSTATAT_ST_SIZE_ETC_BROKEN) */ - -# if HAVE_FSTATAT -# undef fstatat -# define fstatat rpl_fstatat -# endif +#else /* !HAVE_FSTATAT || FSTATAT_ZERO_FLAG_BROKEN */ /* On mingw, the gnulib defines `stat' as a function-like macro; but using it in AT_FUNC_F2 causes compilation failure @@ -98,7 +115,11 @@ stat_func (char const *name, struct stat *st) then give a diagnostic and exit nonzero. Otherwise, this function works just like Solaris' fstatat. */ -# define AT_FUNC_NAME fstatat +# if FSTATAT_ZERO_FLAG_BROKEN +# define AT_FUNC_NAME rpl_fstatat +# else +# define AT_FUNC_NAME fstatat +# endif # define AT_FUNC_F1 lstat # define AT_FUNC_F2 stat_func # define AT_FUNC_USE_F1_COND AT_SYMLINK_NOFOLLOW @@ -112,4 +133,4 @@ stat_func (char const *name, struct stat *st) # undef AT_FUNC_POST_FILE_PARAM_DECLS # undef AT_FUNC_POST_FILE_ARGS -#endif /* ! (HAVE_FSTATAT && ! FSTATAT_ST_SIZE_ETC_BROKEN) */ +#endif /* !HAVE_FSTATAT */