Mercurial > hg > octave-kai > gnulib-hg
changeset 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 |
parents | ebf52f657a28 |
children | f888e5e48e69 |
files | ChangeLog lib/fstatat.c m4/openat.m4 |
diffstat | 3 files changed, 61 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2011-09-03 Paul Eggert <eggert@cs.ucla.edu> + + 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. + 2011-09-03 Karl Berry <karl@gnu.org> * doc/regex.texi (Character Class Operators): Avoid literal ":"
--- 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)
--- 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 @@ 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 <http://lists.gnu.org/archive/html/bug-tar/2011-09/msg00015.html>. + 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 <fcntl.h> + #include <sys/stat.h> + 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 ])