Use ferror(3) to check for errors, rather than inspecting errno. Thanks to
authorMatt Kraai <kraai@debian.org>
Mon, 6 Aug 2001 16:09:09 +0000 (16:09 -0000)
committerMatt Kraai <kraai@debian.org>
Mon, 6 Aug 2001 16:09:09 +0000 (16:09 -0000)
David Douthitt for reporting, and shame on me for writing such crappy code.

coreutils/head.c
head.c

index 0c8ef3d..688c250 100644 (file)
@@ -22,7 +22,6 @@
  *
  */
 
-#include <errno.h>
 #include <stdio.h>
 #include <getopt.h>
 #include <stdlib.h>
@@ -82,10 +81,9 @@ int head_main(int argc, char **argv)
                                printf("==> %s <==\n", argv[optind]);
                        }
                        head(len, fp);
-                       if (errno) {
+                       if (ferror(fp)) {
                                perror_msg("%s", argv[optind]);
                                status = EXIT_FAILURE;
-                               errno = 0;
                        }
                        if (optind < argc - 1)
                                putchar('\n');
diff --git a/head.c b/head.c
index 0c8ef3d..688c250 100644 (file)
--- a/head.c
+++ b/head.c
@@ -22,7 +22,6 @@
  *
  */
 
-#include <errno.h>
 #include <stdio.h>
 #include <getopt.h>
 #include <stdlib.h>
@@ -82,10 +81,9 @@ int head_main(int argc, char **argv)
                                printf("==> %s <==\n", argv[optind]);
                        }
                        head(len, fp);
-                       if (errno) {
+                       if (ferror(fp)) {
                                perror_msg("%s", argv[optind]);
                                status = EXIT_FAILURE;
-                               errno = 0;
                        }
                        if (optind < argc - 1)
                                putchar('\n');