+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>
--- /dev/null
+/* 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;
+}
}
}
-/* 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(). */
#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
<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
#endif
+#ifdef FCHDIR_REPLACEMENT
+/* gnulib internal function. */
+extern void _gl_unregister_fd (int fd);
+#endif
+
+
#ifdef __cplusplus
}
#endif
--- /dev/null
+# 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
+])
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
-# 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,
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])
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])
--- /dev/null
+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
Depends-on:
canonicalize-lgpl
+close
dirfd
dup2
fcntl
-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' \
-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' \