base64: always treat input in binary mode
authorEric Blake <eblake@redhat.com>
Wed, 21 Apr 2010 14:17:59 +0000 (08:17 -0600)
committerEric Blake <eblake@redhat.com>
Thu, 22 Apr 2010 14:42:54 +0000 (08:42 -0600)
Necessary for cygwin.  Technically, this patch is not correct,
in that it clobbers O_APPEND, but it is no different than any
other use of xfreopen to force binary mode, so all such uses
should be fixed at once in a later patch.

* src/base64.c (main): Open input in binary mode.
* THANKS: Update.
Reported by Yutaka Amanai.

THANKS
src/base64.c

diff --git a/THANKS b/THANKS
index 2ea6801..ecad934 100644 (file)
--- a/THANKS
+++ b/THANKS
@@ -636,6 +636,7 @@ Wolfram Kleff                       kleff@cs.uni-bonn.de
 Won-kyu Park                        wkpark@chem.skku.ac.kr
 Yanko Kaneti                        yaneti@declera.com
 Yann Dirson                         dirson@debian.org
+Yutaka Amanai                       yasai-itame1942@jade.plala.or.jp
 Zvi Har'El                          rl@math.technion.ac.il
 
 ;; Local Variables:
index 34569ec..41e9dea 100644 (file)
@@ -29,6 +29,7 @@
 #include "xstrtol.h"
 #include "quote.h"
 #include "quotearg.h"
+#include "xfreopen.h"
 
 #include "base64.h"
 
@@ -289,10 +290,14 @@ main (int argc, char **argv)
     infile = "-";
 
   if (STREQ (infile, "-"))
-    input_fh = stdin;
+    {
+      if (O_BINARY)
+        xfreopen (NULL, "rb", stdin);
+      input_fh = stdin;
+    }
   else
     {
-      input_fh = fopen (infile, "r");
+      input_fh = fopen (infile, "rb");
       if (input_fh == NULL)
         error (EXIT_FAILURE, errno, "%s", infile);
     }