From d638ad2325cc24731a6deda2cb8d530d1c380a3a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 10 Oct 2008 00:06:58 +0200 Subject: [PATCH] New module 'close'. --- ChangeLog | 19 +++++++++++++++++++ lib/close.c | 37 +++++++++++++++++++++++++++++++++++++ lib/fchdir.c | 13 ------------- lib/unistd.in.h | 18 ++++++++++++++++-- m4/close.m4 | 19 +++++++++++++++++++ m4/fchdir.m4 | 1 + m4/unistd_h.m4 | 4 +++- modules/close | 24 ++++++++++++++++++++++++ modules/fchdir | 1 + modules/unistd | 2 ++ 10 files changed, 122 insertions(+), 16 deletions(-) create mode 100644 lib/close.c create mode 100644 m4/close.m4 create mode 100644 modules/close diff --git a/ChangeLog b/ChangeLog index 070a66abc..38a308366 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,25 @@ 2008-10-09 Paolo Bonzini Bruno Haible + New module 'close'. + * modules/close: New file. + * lib/unistd.in.h (close): Move declaration out of the + FCHDIR_REPLACEMENT scope. + (_gl_unregister_fd): New declaration. + * lib/close.c: New file. + * lib/fchdir.c (rpl_close): Remove function. + * m4/close.m4: New file. + * m4/fchdir.m4 (gl_FUNC_FCHDIR): When replacing fchdir, also replace + close. + * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Initialize GNULIB_CLOSE and + REPLACE_CLOSE. + * modules/unistd (Makefile.am): Substitute GNULIB_CLOSE and + REPLACE_CLOSE. + * modules/fchdir (Depends-on): Add close. + +2008-10-09 Paolo Bonzini + Bruno Haible + * lib/fcntl.in.h (open): Simplify conditionals. (_gl_register_fd): New declaration. * lib/fchdir.c (rpl_open): Remove function. diff --git a/lib/close.c b/lib/close.c new file mode 100644 index 000000000..b0464c96b --- /dev/null +++ b/lib/close.c @@ -0,0 +1,37 @@ +/* close replacement. + Copyright (C) 2008 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + + +/* Override close() to call into other gnulib modules. */ + +int +rpl_close (int fd) +#undef close +{ + int retval = close (fd); + +#ifdef FCHDIR_REPLACEMENT + if (retval >= 0) + _gl_unregister_fd (fd); +#endif + + return retval; +} diff --git a/lib/fchdir.c b/lib/fchdir.c index dccb4f19b..84d654687 100644 --- a/lib/fchdir.c +++ b/lib/fchdir.c @@ -105,19 +105,6 @@ _gl_register_fd (int fd, const char *filename) } } -/* Override close(), to keep track of the open file descriptors. */ - -int -rpl_close (int fd) -#undef close -{ - int retval = close (fd); - - if (retval >= 0) - _gl_unregister_fd (fd); - return retval; -} - /* Override opendir() and closedir(), to keep track of the open file descriptors. Needed because there is a function dirfd(). */ diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 82b1f0a81..c7233b125 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -75,6 +75,16 @@ extern int chown (const char *file, uid_t uid, gid_t gid); #endif +#if @GNULIB_CLOSE@ +# if @REPLACE_CLOSE@ +/* Automatically included by modules that need a replacement for close. */ +# undef close +# define close rpl_close +extern int close (int); +# endif +#endif + + #if @GNULIB_DUP2@ # if !@HAVE_DUP2@ /* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if @@ -123,8 +133,6 @@ extern char **environ; . */ extern int fchdir (int /*fd*/); -# define close rpl_close -extern int close (int); # define dup rpl_dup extern int dup (int); # define dup2 rpl_dup2 @@ -379,6 +387,12 @@ 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); +#endif + + #ifdef __cplusplus } #endif diff --git a/m4/close.m4 b/m4/close.m4 new file mode 100644 index 000000000..edfcfec59 --- /dev/null +++ b/m4/close.m4 @@ -0,0 +1,19 @@ +# close.m4 serial 1 +dnl Copyright (C) 2008 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_FUNC_CLOSE], +[ + : +]) + +AC_DEFUN([gl_REPLACE_CLOSE], +[ + AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) + if test $REPLACE_CLOSE != 1; then + AC_LIBOBJ([close]) + fi + REPLACE_CLOSE=1 +]) diff --git a/m4/fchdir.m4 b/m4/fchdir.m4 index 37d3a55b9..eff886bf1 100644 --- a/m4/fchdir.m4 +++ b/m4/fchdir.m4 @@ -15,6 +15,7 @@ AC_DEFUN([gl_FUNC_FCHDIR], AC_DEFINE([FCHDIR_REPLACEMENT], 1, [Define if gnulib's fchdir() replacement is used.]) gl_REPLACE_OPEN + gl_REPLACE_CLOSE gl_CHECK_NEXT_HEADERS([dirent.h]) DIRENT_H='dirent.h' else diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4 index e6eb045ca..21c400c4e 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,4 +1,4 @@ -# unistd_h.m4 serial 13 +# unistd_h.m4 serial 14 dnl Copyright (C) 2006-2008 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -33,6 +33,7 @@ AC_DEFUN([gl_UNISTD_MODULE_INDICATOR], AC_DEFUN([gl_UNISTD_H_DEFAULTS], [ GNULIB_CHOWN=0; AC_SUBST([GNULIB_CHOWN]) + GNULIB_CLOSE=0; AC_SUBST([GNULIB_CLOSE]) GNULIB_DUP2=0; AC_SUBST([GNULIB_DUP2]) GNULIB_ENVIRON=0; AC_SUBST([GNULIB_ENVIRON]) GNULIB_FCHDIR=0; AC_SUBST([GNULIB_FCHDIR]) @@ -61,6 +62,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], HAVE_OS_H=0; AC_SUBST([HAVE_OS_H]) HAVE_SYS_PARAM_H=0; AC_SUBST([HAVE_SYS_PARAM_H]) REPLACE_CHOWN=0; AC_SUBST([REPLACE_CHOWN]) + REPLACE_CLOSE=0; AC_SUBST([REPLACE_CLOSE]) REPLACE_FCHDIR=0; AC_SUBST([REPLACE_FCHDIR]) REPLACE_GETCWD=0; AC_SUBST([REPLACE_GETCWD]) REPLACE_GETPAGESIZE=0; AC_SUBST([REPLACE_GETPAGESIZE]) diff --git a/modules/close b/modules/close new file mode 100644 index 000000000..856ef326a --- /dev/null +++ b/modules/close @@ -0,0 +1,24 @@ +Description: +close() function: close a file or socket. + +Files: +lib/close.c +m4/close.m4 + +Depends-on: +unistd + +configure.ac: +gl_FUNC_CLOSE +gl_UNISTD_MODULE_INDICATOR([close]) + +Makefile.am: + +Include: + + +License: +LGPLv2+ + +Maintainer: +Paolo Bonzini, Simon Josefsson, Bruno Haible diff --git a/modules/fchdir b/modules/fchdir index 366831413..e7d8eec57 100644 --- a/modules/fchdir +++ b/modules/fchdir @@ -8,6 +8,7 @@ m4/fchdir.m4 Depends-on: canonicalize-lgpl +close dirfd dup2 fcntl diff --git a/modules/unistd b/modules/unistd index 492f88f12..95e10d9bd 100644 --- a/modules/unistd +++ b/modules/unistd @@ -25,6 +25,7 @@ unistd.h: unistd.in.h -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \ -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \ -e 's|@''GNULIB_CHOWN''@|$(GNULIB_CHOWN)|g' \ + -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \ -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \ -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \ -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \ @@ -52,6 +53,7 @@ unistd.h: unistd.in.h -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \ -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \ -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \ + -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \ -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \ -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \ -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \ -- 2.11.0