(cksum): Avoid setmode; use POSIX-specified routines instead.
authorPaul Eggert <eggert@cs.ucla.edu>
Mon, 11 Jul 2005 18:21:54 +0000 (18:21 +0000)
committerPaul Eggert <eggert@cs.ucla.edu>
Mon, 11 Jul 2005 18:21:54 +0000 (18:21 +0000)
src/cksum.c

index 0499379..0dce68c 100644 (file)
@@ -199,10 +199,12 @@ cksum (const char *file, bool print_name)
     {
       fp = stdin;
       have_read_stdin = true;
+      if (O_BINARY && ! isatty (STDIN_FILENO))
+       freopen (NULL, "rb", stdin);
     }
   else
     {
-      fp = fopen (file, "r");
+      fp = fopen (file, (O_BINARY ? "rb" : "r"));
       if (fp == NULL)
        {
          error (0, errno, "%s", file);
@@ -210,9 +212,6 @@ cksum (const char *file, bool print_name)
        }
     }
 
-  /* Read input in BINARY mode, unless it is a console device.  */
-  SET_BINARY (fileno (fp));
-
   while ((bytes_read = fread (buf, 1, BUFLEN, fp)) > 0)
     {
       unsigned char *cp = buf;