Mercurial > hg > octave-lyh > gnulib-hg
changeset 11933:1ffad224c413
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.
Signed-off-by: Eric Blake <ebb9@byu.net>
author | Eric Blake <ebb9@byu.net> |
---|---|
date | Tue, 01 Sep 2009 09:18:16 -0600 |
parents | 4073da4a848c |
children | 80567a8f98f8 |
files | 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 |
diffstat | 12 files changed, 46 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- 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.
--- a/lib/close.c +++ b/lib/close.c @@ -33,7 +33,7 @@ int retval = close (fd); #endif -#ifdef FCHDIR_REPLACEMENT +#if REPLACE_FCHDIR if (retval >= 0) _gl_unregister_fd (fd); #endif
--- a/lib/dup-safer.c +++ b/lib/dup-safer.c @@ -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
--- a/lib/dup2.c +++ b/lib/dup2.c @@ -70,7 +70,7 @@ /* 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 @@ # else result = dupfd (fd, desired_fd); # endif -#ifdef FCHDIR_REPLACEMENT +#if REPLACE_FCHDIR if (0 <= result) result = _gl_register_dup (fd, desired_fd); #endif
--- a/lib/dup3.c +++ b/lib/dup3.c @@ -63,7 +63,7 @@ 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 @@ errno = saved_errno; } -#ifdef FCHDIR_REPLACEMENT +#if REPLACE_FCHDIR if (result == newfd) result = _gl_register_dup (oldfd, newfd); #endif @@ -226,7 +226,7 @@ setmode (newfd, O_TEXT); #endif -#ifdef FCHDIR_REPLACEMENT +#if REPLACE_FCHDIR newfd = _gl_register_dup (oldfd, newfd); #endif return newfd;
--- a/lib/fcntl.in.h +++ b/lib/fcntl.in.h @@ -58,11 +58,6 @@ # endif #endif -#ifdef FCHDIR_REPLACEMENT -/* gnulib internal function. */ -extern int _gl_register_fd (int fd, const char *filename); -#endif - #ifdef __cplusplus } #endif
--- a/lib/open.c +++ b/lib/open.c @@ -38,6 +38,7 @@ #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 @@ 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 @@ } #endif -#ifdef FCHDIR_REPLACEMENT +#if REPLACE_FCHDIR if (!REPLACE_OPEN_DIRECTORY && 0 <= fd) fd = _gl_register_fd (fd, filename); #endif
--- a/lib/sys_stat.in.h +++ b/lib/sys_stat.in.h @@ -302,7 +302,7 @@ 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
--- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -248,6 +248,11 @@ # 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 @@ #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
--- a/m4/fchdir.m4 +++ b/m4/fchdir.m4 @@ -8,13 +8,15 @@ [ 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
--- a/m4/sys_stat_h.m4 +++ b/m4/sys_stat_h.m4 @@ -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_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.
--- a/modules/sys_stat +++ b/modules/sys_stat @@ -4,6 +4,7 @@ Files: lib/sys_stat.in.h m4/sys_stat_h.m4 +m4/unistd_h.m4 Depends-on: include_next @@ -31,6 +32,7 @@ -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 && \