Mercurial > hg > octave-lyh > gnulib-hg
changeset 10609:5acc60c1ec66
New module 'close'.
author | Paolo Bonzini <bonzini@gnu.org> |
---|---|
date | Fri, 10 Oct 2008 00:06:58 +0200 |
parents | 9559d8f05cdb |
children | 9202c6340cce |
files | ChangeLog lib/close.c lib/fchdir.c lib/unistd.in.h m4/close.m4 m4/fchdir.m4 m4/unistd_h.m4 modules/close modules/fchdir modules/unistd |
diffstat | 10 files changed, 122 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,22 @@ +2008-10-09 Paolo Bonzini <bonzini@gnu.org> + Bruno Haible <bruno@clisp.org> + + 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 <bonzini@gnu.org> Bruno Haible <bruno@clisp.org>
new file mode 100644 --- /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 <http://www.gnu.org/licenses/>. */ + +#include <config.h> + +/* Specification. */ +#include <unistd.h> + + +/* 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; +}
--- a/lib/fchdir.c +++ b/lib/fchdir.c @@ -105,19 +105,6 @@ } } -/* 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(). */
--- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -75,6 +75,16 @@ #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 @@ <http://www.opengroup.org/susv3xsh/fchdir.html>. */ 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 @@ #endif +#ifdef FCHDIR_REPLACEMENT +/* gnulib internal function. */ +extern void _gl_unregister_fd (int fd); +#endif + + #ifdef __cplusplus } #endif
new file mode 100644 --- /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 +])
--- a/m4/fchdir.m4 +++ b/m4/fchdir.m4 @@ -15,6 +15,7 @@ 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
--- 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_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 @@ 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])
new file mode 100644 --- /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: +<unistd.h> + +License: +LGPLv2+ + +Maintainer: +Paolo Bonzini, Simon Josefsson, Bruno Haible
--- a/modules/fchdir +++ b/modules/fchdir @@ -8,6 +8,7 @@ Depends-on: canonicalize-lgpl +close dirfd dup2 fcntl
--- a/modules/unistd +++ b/modules/unistd @@ -25,6 +25,7 @@ -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 @@ -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' \