fold: Properly report exit status if we fail to open a file

This commit is contained in:
sin 2015-01-25 20:26:30 +00:00
parent e3c51eb17d
commit 8c99cfae86

8
fold.c
View File

@ -73,6 +73,7 @@ main(int argc, char *argv[])
{ {
size_t width = 80; size_t width = 80;
FILE *fp; FILE *fp;
int r = 0;
ARGBEGIN { ARGBEGIN {
case 'b': case 'b':
@ -91,12 +92,13 @@ main(int argc, char *argv[])
usage(); usage();
} ARGEND; } ARGEND;
if (argc == 0) if (argc == 0) {
fold(stdin, width); fold(stdin, width);
else { } else {
for (; argc > 0; argc--, argv++) { for (; argc > 0; argc--, argv++) {
if (!(fp = fopen(argv[0], "r"))) { if (!(fp = fopen(argv[0], "r"))) {
weprintf("fopen %s:", argv[0]); weprintf("fopen %s:", argv[0]);
r = 1;
continue; continue;
} }
fold(fp, width); fold(fp, width);
@ -104,5 +106,5 @@ main(int argc, char *argv[])
} }
} }
return 0; return r;
} }