fchdir: use more consistent macro convention
authorEric Blake <ebb9@byu.net>
Tue, 1 Sep 2009 15:18:16 +0000 (09:18 -0600)
committerEric Blake <ebb9@byu.net>
Thu, 3 Sep 2009 01:14:45 +0000 (19:14 -0600)
* lib/fcntl.in.h (_gl_register_fd): Move declaration to unistd.
* lib/sys_stat.in.h (rpl_fstat): Declare via make-time
REPLACE_FCHDIR, rather than relying on config.h macros.
* lib/unistd.in.h (fchdir): Move all fchdir internal declarations
inside a single make-time REPLACE_FCHDIR block, rather than using
the config.h FCHDIR_REPLACEMENT.
* m4/fchdir.m4 (gl_FUNC_FCHDIR): REPLACE_FCHDIR was already
AC_SUBST'd, also AC_DEFINE it.  Don't define FCHDIR_REPLACEMENT.
Manage fstat replacement.
* m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Pick up
REPLACE_FCHDIR.
* modules/sys_stat (Files): Add m4/unistd_h.m4.
(Makefile.am): Substitute REPLACE_FCHDIR.
* lib/close.c (rpl_close): Use REPLACE_FCHDIR, not
FCHDIR_REPLACEMENT.
* lib/dup-safer.c (dup_safer): Likewise.
* lib/dup2.c (rpl_dup2): Likewise.
* lib/dup3.c (rpl_dup3): Likewise.
* lib/open.c (rpl_open): Likewise.

Signed-off-by: Eric Blake <ebb9@byu.net>
12 files changed:
ChangeLog
lib/close.c
lib/dup-safer.c
lib/dup2.c
lib/dup3.c
lib/fcntl.in.h
lib/open.c
lib/sys_stat.in.h
lib/unistd.in.h
m4/fchdir.m4
m4/sys_stat_h.m4
modules/sys_stat

index 6a45887..3205ba8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,26 @@
 2009-09-02  Eric Blake  <ebb9@byu.net>
 
+       fchdir: use more consistent macro convention
+       * lib/fcntl.in.h (_gl_register_fd): Move declaration to unistd.
+       * lib/sys_stat.in.h (rpl_fstat): Declare via make-time
+       REPLACE_FCHDIR, rather than relying on config.h macros.
+       * lib/unistd.in.h (fchdir): Move all fchdir internal declarations
+       inside a single make-time REPLACE_FCHDIR block, rather than using
+       the config.h FCHDIR_REPLACEMENT.
+       * m4/fchdir.m4 (gl_FUNC_FCHDIR): REPLACE_FCHDIR was already
+       AC_SUBST'd, also AC_DEFINE it.  Don't define FCHDIR_REPLACEMENT.
+       Manage fstat replacement.
+       * m4/sys_stat_h.m4 (gl_SYS_STAT_H_DEFAULTS): Pick up
+       REPLACE_FCHDIR.
+       * modules/sys_stat (Files): Add m4/unistd_h.m4.
+       (Makefile.am): Substitute REPLACE_FCHDIR.
+       * lib/close.c (rpl_close): Use REPLACE_FCHDIR, not
+       FCHDIR_REPLACEMENT.
+       * lib/dup-safer.c (dup_safer): Likewise.
+       * lib/dup2.c (rpl_dup2): Likewise.
+       * lib/dup3.c (rpl_dup3): Likewise.
+       * lib/open.c (rpl_open): Likewise.
+
        fchdir: simplify error handling, and support dup3
        * modules/fchdir (Depends-on): Use strdup-posix, not strdup.  Add
        stdbool, malloc-posix, realloc-posix.
index 0e56dcb..5278f24 100644 (file)
@@ -33,7 +33,7 @@ rpl_close (int fd)
   int retval = close (fd);
 #endif
 
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
   if (retval >= 0)
     _gl_unregister_fd (fd);
 #endif
index 7d9b2be..22b96ba 100644 (file)
@@ -32,7 +32,7 @@
 int
 dup_safer (int fd)
 {
-#if defined F_DUPFD && !defined FCHDIR_REPLACEMENT
+#if defined F_DUPFD && !REPLACE_FCHDIR
   return fcntl (fd, F_DUPFD, STDERR_FILENO + 1);
 #else
   /* fd_safer calls us back, but eventually the recursion unwinds and
index a513e5b..140af1b 100644 (file)
@@ -70,7 +70,7 @@ rpl_dup2 (int fd, int desired_fd)
   /* Correct a cygwin 1.5.x errno value.  */
   else if (result == -1 && errno == EMFILE)
     errno = EBADF;
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
   if (fd != desired_fd && result == desired_fd)
     result = _gl_register_dup (fd, desired_fd);
 #endif
@@ -111,7 +111,7 @@ dup2 (int fd, int desired_fd)
 # else
   result = dupfd (fd, desired_fd);
 # endif
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
   if (0 <= result)
     result = _gl_register_dup (fd, desired_fd);
 #endif
index 3d6f940..879a907 100644 (file)
@@ -63,7 +63,7 @@ dup3 (int oldfd, int newfd, int flags)
        if (!(result < 0 && errno == ENOSYS))
          {
            have_dup3_really = 1;
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
            if (0 <= result)
              result = _gl_register_dup (oldfd, newfd);
 #endif
@@ -184,7 +184,7 @@ dup3 (int oldfd, int newfd, int flags)
        errno = saved_errno;
       }
 
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
       if (result == newfd)
        result = _gl_register_dup (oldfd, newfd);
 #endif
@@ -226,7 +226,7 @@ dup3 (int oldfd, int newfd, int flags)
     setmode (newfd, O_TEXT);
 #endif
 
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
   newfd = _gl_register_dup (oldfd, newfd);
 #endif
   return newfd;
index 959be44..5c63afd 100644 (file)
@@ -58,11 +58,6 @@ extern int open (const char *filename, int flags, ...);
 # endif
 #endif
 
-#ifdef FCHDIR_REPLACEMENT
-/* gnulib internal function.  */
-extern int _gl_register_fd (int fd, const char *filename);
-#endif
-
 #ifdef __cplusplus
 }
 #endif
index 02dd12d..08ecaff 100644 (file)
@@ -38,6 +38,7 @@ orig_open (const char *filename, int flags, mode_t mode)
 #include <string.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <unistd.h>
 
 #ifndef REPLACE_OPEN_DIRECTORY
 # define REPLACE_OPEN_DIRECTORY 0
@@ -102,7 +103,7 @@ open (const char *filename, int flags, ...)
 
   fd = orig_open (filename, flags, mode);
 
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
   /* Implementing fchdir and fdopendir requires the ability to open a
      directory file descriptor.  If open doesn't support that (as on
      mingw), we use a dummy file that behaves the same as directories
@@ -155,7 +156,7 @@ open (const char *filename, int flags, ...)
     }
 #endif
 
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
   if (!REPLACE_OPEN_DIRECTORY && 0 <= fd)
     fd = _gl_register_fd (fd, filename);
 #endif
index 9d511da..b034168 100644 (file)
@@ -302,7 +302,7 @@ extern int rpl_lstat (const char *name, struct stat *buf);
    lstat (p, b))
 #endif
 
-#if defined FCHDIR_REPLACEMENT && REPLACE_OPEN_DIRECTORY
+#if @REPLACE_FCHDIR@
 # define fstat rpl_fstat
 extern int fstat (int fd, struct stat *buf);
 #endif
index f0b5cc4..3a748a6 100644 (file)
@@ -248,6 +248,11 @@ extern int fchdir (int /*fd*/);
 #  define dup rpl_dup
 extern int dup (int);
 
+/* Gnulib internal hooks needed to maintain the fchdir metadata.  */
+extern int _gl_register_fd (int fd, const char *filename);
+extern void _gl_unregister_fd (int fd);
+extern int _gl_register_dup (int oldfd, int newfd);
+
 # endif
 #elif defined GNULIB_POSIXCHECK
 # undef fchdir
@@ -615,14 +620,6 @@ extern ssize_t write (int fd, const void *buf, size_t count);
 #endif
 
 
-#ifdef FCHDIR_REPLACEMENT
-/* gnulib internal function.  */
-extern void _gl_unregister_fd (int fd);
-/* gnulib internal function.  */
-extern int _gl_register_dup (int oldfd, int newfd);
-#endif
-
-
 #ifdef __cplusplus
 }
 #endif
index bcaf056..6597be0 100644 (file)
@@ -8,13 +8,15 @@ AC_DEFUN([gl_FUNC_FCHDIR],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
   AC_REQUIRE([gl_DIRENT_H_DEFAULTS])
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
   AC_CHECK_FUNCS_ONCE([fchdir])
   if test $ac_cv_func_fchdir = no; then
     REPLACE_FCHDIR=1
     AC_LIBOBJ([fchdir])
     gl_PREREQ_FCHDIR
-    AC_DEFINE([FCHDIR_REPLACEMENT], [1],
-      [Define if gnulib's fchdir() replacement is used.])
+    AC_DEFINE([REPLACE_FCHDIR], [1],
+      [Define to 1 if gnulib's fchdir() replacement is used.])
+    REPLACE_FSTAT=1
     gl_REPLACE_OPEN
     gl_REPLACE_CLOSE
     gl_REPLACE_DUP2
index 20c82ed..5113e55 100644 (file)
@@ -1,5 +1,5 @@
-# sys_stat_h.m4 serial 10   -*- Autoconf -*-
-dnl Copyright (C) 2006-2008 Free Software Foundation, Inc.
+# sys_stat_h.m4 serial 11   -*- Autoconf -*-
+dnl Copyright (C) 2006-2009 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
 dnl with or without modifications, as long as this notice is preserved.
@@ -50,6 +50,7 @@ AC_DEFUN([gl_SYS_STAT_MODULE_INDICATOR],
 
 AC_DEFUN([gl_SYS_STAT_H_DEFAULTS],
 [
+  AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for REPLACE_FCHDIR
   GNULIB_LCHMOD=0; AC_SUBST([GNULIB_LCHMOD])
   GNULIB_LSTAT=0;  AC_SUBST([GNULIB_LSTAT])
   dnl Assume proper GNU behavior unless another module says otherwise.
index e4fba73..40f1c18 100644 (file)
@@ -4,6 +4,7 @@ A <sys/stat.h> for systems with missing declarations.
 Files:
 lib/sys_stat.in.h
 m4/sys_stat_h.m4
+m4/unistd_h.m4
 
 Depends-on:
 include_next
@@ -31,6 +32,7 @@ sys/stat.h: sys_stat.in.h
              -e 's|@''HAVE_LSTAT''@|$(HAVE_LSTAT)|g' \
              -e 's|@''REPLACE_LSTAT''@|$(REPLACE_LSTAT)|g' \
              -e 's|@''REPLACE_MKDIR''@|$(REPLACE_MKDIR)|g' \
+             -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \
              -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
              < $(srcdir)/sys_stat.in.h; \
        } > $@-t && \