New module 'close'.
authorPaolo Bonzini <bonzini@gnu.org>
Thu, 9 Oct 2008 22:06:58 +0000 (00:06 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 9 Oct 2008 22:06:58 +0000 (00:06 +0200)
ChangeLog
lib/close.c [new file with mode: 0644]
lib/fchdir.c
lib/unistd.in.h
m4/close.m4 [new file with mode: 0644]
m4/fchdir.m4
m4/unistd_h.m4
modules/close [new file with mode: 0644]
modules/fchdir
modules/unistd

index 070a66a..38a3083 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,25 @@
 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>
+
        * 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 (file)
index 0000000..b0464c9
--- /dev/null
@@ -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;
+}
index dccb4f1..84d6546 100644 (file)
@@ -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().  */
 
index 82b1f0a..c7233b1 100644 (file)
@@ -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;
    <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 @@ 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 (file)
index 0000000..edfcfec
--- /dev/null
@@ -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
+])
index 37d3a55..eff886b 100644 (file)
@@ -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
index e6eb045..21c400c 100644 (file)
@@ -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 (file)
index 0000000..856ef32
--- /dev/null
@@ -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
index 3668314..e7d8eec 100644 (file)
@@ -8,6 +8,7 @@ m4/fchdir.m4
 
 Depends-on:
 canonicalize-lgpl
+close
 dirfd
 dup2
 fcntl
index 492f88f..95e10d9 100644 (file)
@@ -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' \