bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
* [PATCH] binary-io: do not treat set_binary_mode() on stdin/out/err as an error on OS/2
@ 2019-05-24 11:31 KO Myung-Hun
  2019-05-24 20:20 ` Paul Eggert
  2019-05-25 13:41 ` Bruno Haible
  0 siblings, 2 replies; 14+ messages in thread
From: KO Myung-Hun @ 2019-05-24 11:31 UTC (permalink / raw)
  To: bug-gnulib

Setting stdin/out/err to binary mode is allowed on OS/2. But it's not
useful, because it generates stair-output hard to read.

Instead, let's set them to text mode all the time.

This fixes that tee always crashes at startup if stdin or stdout
are not piped.

* lib/binary-io.c (__gl_setmode_check) [__EMX__]: Remove __EMX__ guard.
* lib/binary-io.h (__gl_setmode_check) [__EMX__]: Remove __EMX__ guard.
(set_binary_mode) [__EMX__]: Override mode with O_TEXT if tty.
---
 lib/binary-io.c | 2 +-
 lib/binary-io.h | 8 +++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/binary-io.c b/lib/binary-io.c
index 01e0bf647..03b98681b 100644
--- a/lib/binary-io.c
+++ b/lib/binary-io.c
@@ -19,7 +19,7 @@
 #define BINARY_IO_INLINE _GL_EXTERN_INLINE
 #include "binary-io.h"
 
-#if defined __DJGPP__ || defined __EMX__
+#if defined __DJGPP__
 # include <errno.h>
 # include <unistd.h>
 
diff --git a/lib/binary-io.h b/lib/binary-io.h
index 720b08c75..75881bd1c 100644
--- a/lib/binary-io.h
+++ b/lib/binary-io.h
@@ -53,7 +53,7 @@ __gl_setmode (int fd _GL_UNUSED, int mode _GL_UNUSED)
 }
 #endif
 
-#if defined __DJGPP__ || defined __EMX__
+#if defined __DJGPP__
 extern int __gl_setmode_check (int);
 #else
 BINARY_IO_INLINE int
@@ -70,6 +70,12 @@ BINARY_IO_INLINE int
 set_binary_mode (int fd, int mode)
 {
   int r = __gl_setmode_check (fd);
+#if defined __EMX__
+  /* On OS/2, setting stdin/out/err to binary is not an error, but
+     non-sense.  */
+  if (isatty (fd))
+    mode = O_TEXT;
+#endif
   return r != 0 ? r : __gl_setmode (fd, mode);
 }
 
-- 
2.13.3



^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2019-06-02  9:31 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-24 11:31 [PATCH] binary-io: do not treat set_binary_mode() on stdin/out/err as an error on OS/2 KO Myung-Hun
2019-05-24 20:20 ` Paul Eggert
2019-05-25  3:29   ` KO Myung-Hun
2019-05-25 13:41 ` Bruno Haible
2019-05-25 14:18   ` KO Myung-Hun
2019-05-25 16:31     ` Bruno Haible
2019-05-25 17:14       ` Paul Eggert
2019-05-26  1:48       ` KO Myung-Hun
2019-05-29  0:47         ` Bruno Haible
2019-05-29 13:32           ` KO Myung-Hun
2019-05-30  0:05           ` Paul Eggert
2019-05-30  0:55             ` Bruno Haible
2019-06-02  6:03               ` Paul Eggert
2019-06-02  9:31                 ` Bruno Haible

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).