Use ferror(3) to check for errors, rather than inspecting errno. Thanks to
David Douthitt for reporting, and shame on me for writing such crappy code.
This commit is contained in:
parent
063c1f54ea
commit
2338d3176b
@ -22,7 +22,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -82,10 +81,9 @@ int head_main(int argc, char **argv)
|
|||||||
printf("==> %s <==\n", argv[optind]);
|
printf("==> %s <==\n", argv[optind]);
|
||||||
}
|
}
|
||||||
head(len, fp);
|
head(len, fp);
|
||||||
if (errno) {
|
if (ferror(fp)) {
|
||||||
perror_msg("%s", argv[optind]);
|
perror_msg("%s", argv[optind]);
|
||||||
status = EXIT_FAILURE;
|
status = EXIT_FAILURE;
|
||||||
errno = 0;
|
|
||||||
}
|
}
|
||||||
if (optind < argc - 1)
|
if (optind < argc - 1)
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
4
head.c
4
head.c
@ -22,7 +22,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -82,10 +81,9 @@ int head_main(int argc, char **argv)
|
|||||||
printf("==> %s <==\n", argv[optind]);
|
printf("==> %s <==\n", argv[optind]);
|
||||||
}
|
}
|
||||||
head(len, fp);
|
head(len, fp);
|
||||||
if (errno) {
|
if (ferror(fp)) {
|
||||||
perror_msg("%s", argv[optind]);
|
perror_msg("%s", argv[optind]);
|
||||||
status = EXIT_FAILURE;
|
status = EXIT_FAILURE;
|
||||||
errno = 0;
|
|
||||||
}
|
}
|
||||||
if (optind < argc - 1)
|
if (optind < argc - 1)
|
||||||
putchar('\n');
|
putchar('\n');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user