* 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>
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.
int retval = close (fd);
#endif
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
if (retval >= 0)
_gl_unregister_fd (fd);
#endif
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
/* 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
# else
result = dupfd (fd, desired_fd);
# endif
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
if (0 <= result)
result = _gl_register_dup (fd, desired_fd);
#endif
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
errno = saved_errno;
}
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
if (result == newfd)
result = _gl_register_dup (oldfd, newfd);
#endif
setmode (newfd, O_TEXT);
#endif
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
newfd = _gl_register_dup (oldfd, newfd);
#endif
return newfd;
# endif
#endif
-#ifdef FCHDIR_REPLACEMENT
-/* gnulib internal function. */
-extern int _gl_register_fd (int fd, const char *filename);
-#endif
-
#ifdef __cplusplus
}
#endif
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <unistd.h>
#ifndef REPLACE_OPEN_DIRECTORY
# define REPLACE_OPEN_DIRECTORY 0
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
}
#endif
-#ifdef FCHDIR_REPLACEMENT
+#if REPLACE_FCHDIR
if (!REPLACE_OPEN_DIRECTORY && 0 <= fd)
fd = _gl_register_fd (fd, filename);
#endif
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
# 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
#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
[
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
-# 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.
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.
Files:
lib/sys_stat.in.h
m4/sys_stat_h.m4
+m4/unistd_h.m4
Depends-on:
include_next
-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 && \