From e91216b238f2af78257bd943db0b22b289d172cc Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sat, 3 Sep 2011 10:03:22 -0700 Subject: [PATCH] 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 . * 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. --- ChangeLog | 12 ++++++++++++ lib/fstatat.c | 20 +++++++++++++++++--- m4/openat.m4 | 35 ++++++++++++++++++++++++++++++++--- 3 files changed, 61 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2665c432e..1301290f3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-09-03 Paul Eggert + + 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 + . + * 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. + 2011-09-03 Karl Berry * doc/regex.texi (Character Class Operators): Avoid literal ":" diff --git a/lib/fstatat.c b/lib/fstatat.c index a904e4326..f1bed737f 100644 --- a/lib/fstatat.c +++ b/lib/fstatat.c @@ -46,19 +46,33 @@ orig_fstatat (int fd, char const *filename, struct stat *buf, int flags) # 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) diff --git a/m4/openat.m4 b/m4/openat.m4 index 5683650d0..149b86476 100644 --- a/m4/openat.m4 +++ b/m4/openat.m4 @@ -1,4 +1,4 @@ -# serial 35 +# serial 36 # See if we need to use our replacement for Solaris' openat et al functions. dnl Copyright (C) 2004-2011 Free Software Foundation, Inc. @@ -164,8 +164,37 @@ AC_DEFUN([gl_FUNC_FSTATAT], if test $ac_cv_func_fstatat = no; then HAVE_FSTATAT=0 - elif test $gl_cv_func_lstat_dereferences_slashed_symlink != yes; then - REPLACE_FSTATAT=1 + else + dnl Test for an AIX 7.1 bug; see + dnl . + AC_CACHE_CHECK([whether fstatat (AT_FDCWD, ..., 0) works], + [gl_cv_func_fstatat_AT_FDCWD_0], + [gl_cv_func_fstatat_AT_FDCWD_0=no + echo xxx >conftest.file + AC_RUN_IFELSE( + [AC_LANG_SOURCE( + [[ + #include + #include + int + main (void) + { + struct stat a; + return fstatat (AT_FDCWD, "conftest.file", &a, 0) != 0; + } + ]])], + [gl_cv_func_fstatat_AT_FDCWD_0=yes])]) + + case $gl_cv_func_fstatat_AT_FDCWD_0+$gl_cv_func_lstat_dereferences_slashed_symlink in + yes+yes) ;; + *) REPLACE_FSTATAT=1 + if test $gl_cv_func_fstatat_AT_FDCWD_0 != yes; then + AC_DEFINE([FSTATAT_AT_FDCWD_0_BROKEN], [1], + [Define to 1 if fstatat (AT_FDCWD, ..., 0) does not work, + as in AIX 7.1.]) + fi + ;; + esac fi ]) -- 2.11.0