bug-gnulib
[Top][All Lists]
Advanced

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

[PATCH] pipe-posix: new module


From: Eric Blake
Subject: [PATCH] pipe-posix: new module
Date: Fri, 10 Dec 2010 15:45:31 -0700

* modules/pipe-posix: New file.
* m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Set default.
(gl_UNISTD_H): Check for declaration.
* modules/unistd (Makefile.am): Substitute it.
* lib/unistd.in.h (pipe): Provide it for mingw.
* doc/posix-functions/pipe.texi (pipe): Update documentation.
* MODULES.html.sh (File descriptor based Input/Output): Likewise.

Signed-off-by: Eric Blake <address@hidden>
---

I'm pushing this.  The module could perhaps be improved (for example,
since it is just a #define rather than a replacement function, it
fails the POSIX aspect of being able to pass a function pointer to
pipe around), and testing I/O through the pipe is impossible without
either threading or spawning a child process, all of which seem rather
complex given how simple the module itself is.  The module name 'pipe'
is already claimed for an unrelated application-level wrapper around
both pipe(2) and the notion of a child process.

 ChangeLog                     |   11 +++++++++++
 MODULES.html.sh               |    1 +
 doc/posix-functions/pipe.texi |    8 ++++----
 lib/unistd.in.h               |   24 ++++++++++++++++++++++--
 m4/unistd_h.m4                |    3 ++-
 modules/pipe-posix            |   22 ++++++++++++++++++++++
 modules/unistd                |    1 +
 7 files changed, 63 insertions(+), 7 deletions(-)
 create mode 100644 modules/pipe-posix

diff --git a/ChangeLog b/ChangeLog
index b1ad470..29849ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-12-10  Eric Blake  <address@hidden>
+
+       pipe-posix: new module
+       * modules/pipe-posix: New file.
+       * m4/unistd_h.m4 (gl_UNISTD_H_DEFAULTS): Set default.
+       (gl_UNISTD_H): Check for declaration.
+       * modules/unistd (Makefile.am): Substitute it.
+       * lib/unistd.in.h (pipe): Provide it for mingw.
+       * doc/posix-functions/pipe.texi (pipe): Update documentation.
+       * MODULES.html.sh (File descriptor based Input/Output): Likewise.
+
 2010-12-07  Bruno Haible  <address@hidden>

        unistr/u8-strcmp: Avoid collision with libc function on Solaris 11.
diff --git a/MODULES.html.sh b/MODULES.html.sh
index 983953c..456497f 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -2649,6 +2649,7 @@ func_all_modules ()
   func_module full-write
   func_module binary-io
   func_module isapipe
+  func_module pipe-posix
   func_module pipe2
   func_module pipe2-safer
   func_end_table
diff --git a/doc/posix-functions/pipe.texi b/doc/posix-functions/pipe.texi
index b8cc508..420e400 100644
--- a/doc/posix-functions/pipe.texi
+++ b/doc/posix-functions/pipe.texi
@@ -4,15 +4,15 @@ pipe

 POSIX specification:@* 
@url{http://www.opengroup.org/onlinepubs/9699919799/functions/pipe.html}

-Gnulib module: ---
+Gnulib module: pipe-posix

 Portability problems fixed by Gnulib:
 @itemize
address@hidden
+This function is missing on some platforms:
+mingw.
 @end itemize

 Portability problems not fixed by Gnulib:
 @itemize
address@hidden
-This function is missing on some platforms:
-mingw.
 @end itemize
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
index 4834e37..571afa1 100644
--- a/lib/unistd.in.h
+++ b/lib/unistd.in.h
@@ -82,10 +82,14 @@
 # include <stdlib.h>
 #endif

-/* mingw declares getcwd in <io.h>, not in <unistd.h>.  */
-#if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
+/* mingw declares getcwd in <io.h>, not in <unistd.h>.  It also provides
+   _pipe in <io.h>, but that requires _O_BINARY from <fcntl.h>.  */
+#if ((@GNULIB_GETCWD@ || @GNULIB_PIPE@ || defined GNULIB_POSIXCHECK) \
      && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
 # include <io.h>
+# if @GNULIB_PIPE@
+#  include <fcntl.h>
+# endif
 #endif

 /* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.  */
@@ -972,6 +976,22 @@ _GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE 
on pipes on some "
 #endif


+#if @GNULIB_PIPE@
+/* Create a pipe, defaulting to O_BINARY mode.
+   Store the read-end as fd[0] and the write-end as fd[1].
+   Return 0 upon success, or -1 with errno set upon failure.  */
+# if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+#  define pipe(fd) _pipe (fd, 4096, _O_BINARY)
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef pipe
+# if HAVE_RAW_DECL_PIPE
+_GL_WARN_ON_USE (pipe, "pipe is unportable - "
+                 "use gnulib module pipe for portability");
+# endif
+#endif
+
+
 #if @GNULIB_PIPE2@
 /* Create a pipe, applying the given flags when opening the read-end of the
    pipe and the write-end of the pipe.
diff --git a/m4/unistd_h.m4 b/m4/unistd_h.m4
index e2f7f2b..0690951 100644
--- a/m4/unistd_h.m4
+++ b/m4/unistd_h.m4
@@ -38,7 +38,7 @@ AC_DEFUN([gl_UNISTD_H],
     ]], [chown dup2 dup3 environ euidaccess faccessat fchdir fchownat
     fsync ftruncate getcwd getdomainname getdtablesize getgroups
     gethostname getlogin getlogin_r getpagesize getusershell setusershell
-    endusershell lchown link linkat lseek pipe2 pread pwrite readlink
+    endusershell lchown link linkat lseek pipe pipe2 pread pwrite readlink
     readlinkat rmdir sleep symlink symlinkat ttyname_r unlink unlinkat
     usleep])
 ])
@@ -78,6 +78,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS],
   GNULIB_LINK=0;             AC_SUBST([GNULIB_LINK])
   GNULIB_LINKAT=0;           AC_SUBST([GNULIB_LINKAT])
   GNULIB_LSEEK=0;            AC_SUBST([GNULIB_LSEEK])
+  GNULIB_PIPE=0;             AC_SUBST([GNULIB_PIPE])
   GNULIB_PIPE2=0;            AC_SUBST([GNULIB_PIPE2])
   GNULIB_PREAD=0;            AC_SUBST([GNULIB_PREAD])
   GNULIB_PWRITE=0;           AC_SUBST([GNULIB_PWRITE])
diff --git a/modules/pipe-posix b/modules/pipe-posix
new file mode 100644
index 0000000..9f753db
--- /dev/null
+++ b/modules/pipe-posix
@@ -0,0 +1,22 @@
+Description:
+Creation of a pipe.
+
+Files:
+
+Depends-on:
+unistd
+
+configure.ac:
+AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+gl_UNISTD_MODULE_INDICATOR([pipe])
+
+Makefile.am:
+
+Include:
+<unistd.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Eric Blake
diff --git a/modules/unistd b/modules/unistd
index 344a189..e2475dd 100644
--- a/modules/unistd
+++ b/modules/unistd
@@ -52,6 +52,7 @@ unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) 
$(WARN_ON_USE_H)
              -e 's|@''GNULIB_LINK''@|$(GNULIB_LINK)|g' \
              -e 's|@''GNULIB_LINKAT''@|$(GNULIB_LINKAT)|g' \
              -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \
+             -e 's|@''GNULIB_PIPE''@|$(GNULIB_PIPE)|g' \
              -e 's|@''GNULIB_PIPE2''@|$(GNULIB_PIPE2)|g' \
              -e 's|@''GNULIB_PREAD''@|$(GNULIB_PREAD)|g' \
              -e 's|@''GNULIB_PWRITE''@|$(GNULIB_PWRITE)|g' \
-- 
1.7.3.2




reply via email to

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