bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] use gnulib modules close (new) and open to hook into open/cl


From: Bruno Haible
Subject: Re: [PATCH] use gnulib modules close (new) and open to hook into open/close
Date: Thu, 9 Oct 2008 23:48:17 +0200
User-agent: KMail/1.5.4

Part 3 committed like this:

2008-10-09  Paolo Bonzini  <address@hidden>
            Bruno Haible  <address@hidden>

        * lib/fcntl.in.h (open): Simplify conditionals.
        (_gl_register_fd): New declaration.
        * lib/fchdir.c (rpl_open): Remove function.
        * lib/open.c: When FCHDIR_REPLACEMENT is defined, compile the file
        also.
        (open): When FCHDIR_REPLACEMENT is defined, invoke _gl_register_fd.
        * m4/fchdir.m4 (gl_FUNC_FCHDIR): When replacing fchdir, also replace
        open.

--- lib/fchdir.c.orig   2008-10-09 13:38:05.000000000 +0200
+++ lib/fchdir.c        2008-10-09 13:34:28.000000000 +0200
@@ -105,7 +105,7 @@
     }
 }
 
-/* Override open() and close(), to keep track of the open file descriptors.  */
+/* Override close(), to keep track of the open file descriptors.  */
 
 int
 rpl_close (int fd)
@@ -118,39 +118,6 @@
   return retval;
 }
 
-int
-rpl_open (const char *filename, int flags, ...)
-#undef open
-{
-  mode_t mode;
-  int fd;
-  struct stat statbuf;
-
-  mode = 0;
-  if (flags & O_CREAT)
-    {
-      va_list arg;
-      va_start (arg, flags);
-
-      /* If mode_t is narrower than int, use the promoted type (int),
-        not mode_t.  Use sizeof to guess whether mode_t is narrower;
-        we don't know of any practical counterexamples.  */
-      mode = (sizeof (mode_t) < sizeof (int)
-             ? va_arg (arg, int)
-             : va_arg (arg, mode_t));
-
-      va_end (arg);
-    }
-#if defined GNULIB_OPEN && ((defined _WIN32 || defined __WIN32__) && ! defined 
__CYGWIN__)
-  if (strcmp (filename, "/dev/null") == 0)
-    filename = "NUL";
-#endif
-  fd = open (filename, flags, mode);
-  if (fd >= 0)
-    _gl_register_fd (fd, filename);
-  return fd;
-}
-
 /* Override opendir() and closedir(), to keep track of the open file
    descriptors.  Needed because there is a function dirfd().  */
 
--- lib/fcntl.in.h.orig 2008-10-09 13:38:05.000000000 +0200
+++ lib/fcntl.in.h      2008-10-09 13:33:50.000000000 +0200
@@ -48,10 +48,17 @@
 extern "C" {
 #endif
 
-#if (@GNULIB_OPEN@ && @REPLACE_OPEN@) || defined FCHDIR_REPLACEMENT
-# undef open
-# define open rpl_open
+#if @GNULIB_OPEN@
+# if @REPLACE_OPEN@
+#  undef open
+#  define open rpl_open
 extern int open (const char *filename, int flags, ...);
+# endif
+#endif
+
+#ifdef FCHDIR_REPLACEMENT
+/* gnulib internal function.  */
+extern void _gl_register_fd (int fd, const char *filename);
 #endif
 
 #ifdef __cplusplus
--- lib/open.c.orig     2008-10-09 13:38:05.000000000 +0200
+++ lib/open.c  2008-10-09 13:33:50.000000000 +0200
@@ -33,14 +33,11 @@
 /* Specification.  */
 #include <fcntl.h>
 
-/* If the fchdir replacement is used, open() is defined in fchdir.c.  */
-#ifndef FCHDIR_REPLACEMENT
-
-# include <errno.h>
-# include <stdarg.h>
-# include <string.h>
-# include <sys/types.h>
-# include <sys/stat.h>
+#include <errno.h>
+#include <stdarg.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 int
 open (const char *filename, int flags, ...)
@@ -64,12 +61,12 @@
       va_end (arg);
     }
 
-# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
   if (strcmp (filename, "/dev/null") == 0)
     filename = "NUL";
-# endif
+#endif
 
-# if OPEN_TRAILING_SLASH_BUG
+#if OPEN_TRAILING_SLASH_BUG
   /* If the filename ends in a slash and one of O_CREAT, O_WRONLY, O_RDWR
      is specified, then fail.
      Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
@@ -100,11 +97,11 @@
          return -1;
        }
     }
-# endif
+#endif
 
   fd = orig_open (filename, flags, mode);
 
-# if OPEN_TRAILING_SLASH_BUG
+#if OPEN_TRAILING_SLASH_BUG
   /* If the filename ends in a slash and fd does not refer to a directory,
      then fail.
      Rationale: POSIX <http://www.opengroup.org/susv3/basedefs/xbd_chap04.html>
@@ -132,8 +129,12 @@
            }
        }
     }
-# endif
+#endif
+
+#ifdef FCHDIR_REPLACEMENT
+  if (fd >= 0)
+    _gl_register_fd (fd, filename);
+#endif
 
   return fd;
 }
-#endif
--- m4/fchdir.m4.orig   2008-10-09 13:38:05.000000000 +0200
+++ m4/fchdir.m4        2008-10-09 13:36:48.000000000 +0200
@@ -1,5 +1,5 @@
-# fchdir.m4 serial 4
-dnl Copyright (C) 2006-2007 Free Software Foundation, Inc.
+# fchdir.m4 serial 5
+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,
 dnl with or without modifications, as long as this notice is preserved.
@@ -14,6 +14,7 @@
     gl_PREREQ_FCHDIR
     AC_DEFINE([FCHDIR_REPLACEMENT], 1,
       [Define if gnulib's fchdir() replacement is used.])
+    gl_REPLACE_OPEN
     gl_CHECK_NEXT_HEADERS([dirent.h])
     DIRENT_H='dirent.h'
   else





reply via email to

[Prev in Thread] Current Thread [Next in Thread]