From 1a661ca2492486e7e04e6ea3396a0be1531a51d5 Mon Sep 17 00:00:00 2001
From: Bruno Haible <bruno@clisp.org>
Date: Sun, 23 Aug 2009 10:46:39 +0200
Subject: [PATCH] Support O_TEXT, O_BINARY on all platforms.

---
 ChangeLog   | 6 ++++++
 lib/pipe2.c | 9 ++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 868272b551..ee8dd55cd9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,12 @@
+2009-08-23  Bruno Haible  <bruno@clisp.org>
+
+	* lib/pipe2.c (pipe2): Support O_TEXT, O_BINARY on all platforms.
+	Reported by Eric Blake.
+
 2009-08-23  Bruno Haible  <bruno@clisp.org>
 
 	* lib/pipe2.c (pipe2): Fix test of fcntl's return value.
+	Reported by Eric Blake.
 
 2009-08-23  Bruno Haible  <bruno@clisp.org>
 
diff --git a/lib/pipe2.c b/lib/pipe2.c
index d40c4cda8e..805c3f560f 100644
--- a/lib/pipe2.c
+++ b/lib/pipe2.c
@@ -52,7 +52,7 @@ int
 pipe2 (int fd[2], int flags)
 {
   /* Check the supported flags.  */
-  if ((flags & ~(O_CLOEXEC | O_NONBLOCK)) != 0)
+  if ((flags & ~(O_CLOEXEC | O_NONBLOCK | O_TEXT | O_BINARY)) != 0)
     {
       errno = EINVAL;
       return -1;
@@ -87,6 +87,13 @@ pipe2 (int fd[2], int flags)
 	goto fail;
     }
 
+#if O_BINARY
+  if (flags & O_BINARY)
+    setmode (fd, O_BINARY);
+  else if (flags & O_TEXT)
+    setmode (fd, O_TEXT);
+#endif
+
   return 0;
 
  fail:
-- 
2.30.2