openat: move fstatat and unlinkat into correct files
authorEric Blake <ebb9@byu.net>
Sat, 19 Sep 2009 11:50:30 +0000 (05:50 -0600)
committerEric Blake <ebb9@byu.net>
Sat, 19 Sep 2009 19:49:59 +0000 (13:49 -0600)
Code motion, should be no semantic changes.

* m4/openat.m4 (gl_FUNC_OPENAT): Adjust which files will be
compiled.
* lib/openat.c (fstatat, unlinkat): Move...
* lib/fstatat.c (fstatat): ...into correct files.
* lib/unlinkat.c (unlinkat): Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/fstatat.c
lib/openat.c
lib/unlinkat.c
m4/openat.m4

index 99e0840..1b9f09a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
 2009-09-19  Eric Blake  <ebb9@byu.net>
 
+       openat: move fstatat and unlinkat into correct files
+       * m4/openat.m4 (gl_FUNC_OPENAT): Adjust which files will be
+       compiled.
+       * lib/openat.c (fstatat, unlinkat): Move...
+       * lib/fstatat.c (fstatat): ...into correct files.
+       * lib/unlinkat.c (unlinkat): Likewise.
+
        openat: fix unlinkat bugs on Solaris 9
        * lib/unlinkat.c (unlinkat): New file.
        * modules/openat (Depends-on): Add unlink.
index 59d7422..1c6c2d3 100644 (file)
@@ -25,7 +25,9 @@
 #include <fcntl.h>
 #include <string.h>
 
-#undef fstatat
+#if HAVE_FSTATAT
+
+# undef fstatat
 
 /* fstatat should always follow symbolic links that end in /, but on
    Solaris 9 it doesn't if AT_SYMLINK_NOFOLLOW is specified.
@@ -62,3 +64,47 @@ rpl_fstatat (int fd, char const *file, struct stat *st, int flag)
     }
   return result;
 }
+
+#else /* !HAVE_FSTATAT */
+
+/* On mingw, the gnulib <sys/stat.h> 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
+stat_func (char const *name, struct stat *st)
+{
+  return stat (name, st);
+}
+
+/* Likewise, if there is no native `lstat', then the gnulib
+   <sys/stat.h> defined it as stat, which also needs adjustment.  */
+# if !HAVE_LSTAT
+#  undef lstat
+#  define lstat stat_func
+# endif
+
+/* Replacement for Solaris' function by the same name.
+   <http://www.google.com/search?q=fstatat+site:docs.sun.com>
+   First, try to simulate it via l?stat ("/proc/self/fd/FD/FILE").
+   Failing that, simulate it via save_cwd/fchdir/(stat|lstat)/restore_cwd.
+   If either the save_cwd or the restore_cwd fails (relatively unlikely),
+   then give a diagnostic and exit nonzero.
+   Otherwise, this function works just like Solaris' fstatat.  */
+
+# define AT_FUNC_NAME fstatat
+# define AT_FUNC_F1 lstat
+# define AT_FUNC_F2 stat_func
+# define AT_FUNC_USE_F1_COND AT_SYMLINK_NOFOLLOW
+# define AT_FUNC_POST_FILE_PARAM_DECLS , struct stat *st, int flag
+# define AT_FUNC_POST_FILE_ARGS        , st
+# include "at-func.c"
+# undef AT_FUNC_NAME
+# undef AT_FUNC_F1
+# undef AT_FUNC_F2
+# undef AT_FUNC_USE_F1_COND
+# undef AT_FUNC_POST_FILE_PARAM_DECLS
+# undef AT_FUNC_POST_FILE_ARGS
+
+#endif /* !HAVE_FSTATAT */
index a0d0ab4..2a194e8 100644 (file)
@@ -156,65 +156,3 @@ openat_needs_fchdir (void)
 
   return needs_fchdir;
 }
-
-/* On mingw, the gnulib <sys/stat.h> 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
-stat_func (char const *name, struct stat *st)
-{
-  return stat (name, st);
-}
-
-/* Likewise, if there is no native `lstat', then the gnulib
-   <sys/stat.h> defined it as stat, which also needs adjustment.  */
-#if !HAVE_LSTAT
-# undef lstat
-# define lstat stat_func
-#endif
-
-/* Replacement for Solaris' function by the same name.
-   <http://www.google.com/search?q=fstatat+site:docs.sun.com>
-   First, try to simulate it via l?stat ("/proc/self/fd/FD/FILE").
-   Failing that, simulate it via save_cwd/fchdir/(stat|lstat)/restore_cwd.
-   If either the save_cwd or the restore_cwd fails (relatively unlikely),
-   then give a diagnostic and exit nonzero.
-   Otherwise, this function works just like Solaris' fstatat.  */
-
-#define AT_FUNC_NAME fstatat
-#define AT_FUNC_F1 lstat
-#define AT_FUNC_F2 stat_func
-#define AT_FUNC_USE_F1_COND AT_SYMLINK_NOFOLLOW
-#define AT_FUNC_POST_FILE_PARAM_DECLS , struct stat *st, int flag
-#define AT_FUNC_POST_FILE_ARGS        , st
-#include "at-func.c"
-#undef AT_FUNC_NAME
-#undef AT_FUNC_F1
-#undef AT_FUNC_F2
-#undef AT_FUNC_USE_F1_COND
-#undef AT_FUNC_POST_FILE_PARAM_DECLS
-#undef AT_FUNC_POST_FILE_ARGS
-
-/* Replacement for Solaris' function by the same name.
-   <http://www.google.com/search?q=unlinkat+site:docs.sun.com>
-   First, try to simulate it via (unlink|rmdir) ("/proc/self/fd/FD/FILE").
-   Failing that, simulate it via save_cwd/fchdir/(unlink|rmdir)/restore_cwd.
-   If either the save_cwd or the restore_cwd fails (relatively unlikely),
-   then give a diagnostic and exit nonzero.
-   Otherwise, this function works just like Solaris' unlinkat.  */
-
-#define AT_FUNC_NAME unlinkat
-#define AT_FUNC_F1 rmdir
-#define AT_FUNC_F2 unlink
-#define AT_FUNC_USE_F1_COND AT_REMOVEDIR
-#define AT_FUNC_POST_FILE_PARAM_DECLS , int flag
-#define AT_FUNC_POST_FILE_ARGS        /* empty */
-#include "at-func.c"
-#undef AT_FUNC_NAME
-#undef AT_FUNC_F1
-#undef AT_FUNC_F2
-#undef AT_FUNC_USE_F1_COND
-#undef AT_FUNC_POST_FILE_PARAM_DECLS
-#undef AT_FUNC_POST_FILE_ARGS
index bf5d5b8..7302252 100644 (file)
@@ -28,7 +28,9 @@
 
 #include "openat.h"
 
-#undef unlinkat
+#if HAVE_UNLINKAT
+
+# undef unlinkat
 
 /* unlinkat without AT_REMOVEDIR does not honor trailing / on Solaris
    9.  Solve it in a similar manner to unlink.  */
@@ -75,3 +77,29 @@ rpl_unlinkat (int fd, char const *name, int flag)
     result = unlinkat (fd, name, flag);
   return result;
 }
+
+#else /* !HAVE_UNLINKAT */
+
+/* Replacement for Solaris' function by the same name.
+   <http://www.google.com/search?q=unlinkat+site:docs.sun.com>
+   First, try to simulate it via (unlink|rmdir) ("/proc/self/fd/FD/FILE").
+   Failing that, simulate it via save_cwd/fchdir/(unlink|rmdir)/restore_cwd.
+   If either the save_cwd or the restore_cwd fails (relatively unlikely),
+   then give a diagnostic and exit nonzero.
+   Otherwise, this function works just like Solaris' unlinkat.  */
+
+# define AT_FUNC_NAME unlinkat
+# define AT_FUNC_F1 rmdir
+# define AT_FUNC_F2 unlink
+# define AT_FUNC_USE_F1_COND AT_REMOVEDIR
+# define AT_FUNC_POST_FILE_PARAM_DECLS , int flag
+# define AT_FUNC_POST_FILE_ARGS        /* empty */
+# include "at-func.c"
+# undef AT_FUNC_NAME
+# undef AT_FUNC_F1
+# undef AT_FUNC_F2
+# undef AT_FUNC_USE_F1_COND
+# undef AT_FUNC_POST_FILE_PARAM_DECLS
+# undef AT_FUNC_POST_FILE_ARGS
+
+#endif /* !HAVE_UNLINKAT */
index e02a11c..b824393 100644 (file)
@@ -1,4 +1,4 @@
-# serial 22
+# serial 23
 # See if we need to use our replacement for Solaris' openat et al functions.
 
 dnl Copyright (C) 2004-2009 Free Software Foundation, Inc.
@@ -25,7 +25,7 @@ AC_DEFUN([gl_FUNC_OPENAT],
   AC_LIBOBJ([openat-proc])
   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
   AC_CHECK_FUNCS_ONCE([lchmod])
-  AC_REPLACE_FUNCS([fchmodat mkdirat openat])
+  AC_REPLACE_FUNCS([fchmodat fstatat mkdirat openat unlinkat])
   AC_REQUIRE([AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK])
   case $ac_cv_func_openat+$ac_cv_func_lstat_dereferences_slashed_symlink in
   yes+yes) ;;