Use xbinary-io gnulib module to set mode of stdin/stdout
authorReuben Thomas <rrt@sc3d.org>
Mon, 22 Jan 2018 13:40:41 +0000 (13:40 +0000)
committerReuben Thomas <rrt@sc3d.org>
Tue, 23 Jan 2018 07:02:42 +0000 (07:02 +0000)
Also isatty module to detect ttys. No longer need DOS/Windows/etc.-specific
ifdefs.

bootstrap.conf
lib/.gitignore
m4/.gitignore
src/task.c

index 08f030ec8cceacfb077fdd7849c360cfc47c9008..83499795e51b5900647c44cb25eee873df6d2549 100644 (file)
@@ -1,4 +1,4 @@
-# bootstrap.conf (Recode) version 2018-01-17
+# bootstrap.conf (Recode) version 2018-01-22
 
 # This file is part of Recode.
 #
@@ -54,6 +54,7 @@ gnulib_modules='
         getopt-posix
         gettext-h
         hash
+        isatty
         localcharset
         manywarnings
         pathmax
@@ -66,6 +67,7 @@ gnulib_modules='
         utime
         vprintf-posix
         xalloc
+        xbinary-io
 '
 
 # Copyright holder
index 1246175f426e9b055e0a0064109eec479b48ae5a..82ad8fbe354b265413705946abe084550c5b811a 100644 (file)
 /stat.c
 /sys_stat.in.h
 /sys/stat.h
+/binary-io.c
+/binary-io.h
+/fcntl.in.h
+/fcntl.h
+/isatty.c
+/xbinary-io.c
+/xbinary-io.h
index a6476cb5c6b435f6977015ae39c8c77b2ccbd6d9..78a5c845c9d0b594a522c206aaab2a17bbe52d33 100644 (file)
@@ -129,3 +129,5 @@ gnulib-comp.m4
 /stat-time.m4
 /stat.m4
 /sys_stat_h.m4
+/fcntl_h.m4
+/isatty.m4
index 3d9cd553b133c4d9f7d5cb0aadeeceb616554ff0..c37d7bf765d9fa621924574d79d439ee603f575e 100644 (file)
@@ -24,6 +24,8 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 
+#include "xbinary-io.h"
+
 /* Buffer size used in transform_mere_copy.  */
 #define BUFFER_SIZE (16 * 1024)
 \f
@@ -547,12 +549,6 @@ recode_delete_task (RECODE_TASK task)
   return true;
 }
 
-#if DOSWIN_OR_OS2
-# include <unistd.h>           /* for isatty */
-# include <fcntl.h>            /* for O_BINARY and _fmode */
-# include <io.h>               /* for setmode */
-#endif
-
 /*------------------------------------------------------------------------.
 | Execute the conversion sequence for a recoding TASK, using the selected |
 | strategy whenever more than one conversion step is needed.  If no       |
@@ -594,27 +590,17 @@ recode_perform_task (RECODE_TASK task)
       break;
     }
 
-#if DOSWIN_OR_OS2
-  /* Don't switch the console device to binary mode.  On several DOSish
-     systems this has unpleasant side effects.  For example, the Ctrl-Z
+  /* Switch stdin and stdout to binary mode unless they are ttys, as this has
+     nasty side-effects on several DOSish systems.  For example, the Ctrl-Z
      character is no longer interpreted as EOF, and thus the poor user cannot
      signal end of input; the INTR character also doesn't work, so they cannot
      even interrupt the program, and are stuck.  On the other hand, output to
      the screen doesn't have to follow the end-of-line format exactly, since
      it is going to be discarded anyway.  */
   if (task->input.name && !*task->input.name && !isatty (fileno (stdin)))
-    setmode (fileno (stdin), O_BINARY);
+    xset_binary_mode (fileno (stdin), O_BINARY);
   if (task->output.name && !*task->output.name && !isatty (fileno (stdout)))
-    setmode (fileno (stdout), O_BINARY);
-# ifdef __EMX__
-  {
-    extern int _fmode_bin;
-    _fmode_bin = 1;
-  }
-# else
-  _fmode = O_BINARY;
-# endif
-#endif
+    xset_binary_mode (fileno (stdout), O_BINARY);
 
   return perform_sequence (task, strategy);
 }