diff options
author | Thomas Voss <mail@thomasvoss.com> | 2022-02-08 00:49:51 +0100 |
---|---|---|
committer | Thomas Voss <mail@thomasvoss.com> | 2022-02-08 00:49:51 +0100 |
commit | ed106c3e0b7318bd55455e5f8df02f746b6216f5 (patch) | |
tree | b1d7ea40aa35e6507da35888463a34211abeada0 /center.c | |
parent | a3183ff88a1aaac66bd49f258fdd02fdeff421ca (diff) |
Don't exit when fopen(3) returns NULL
On failure to open a file the program should print a diagnostic
message to the standard error and move on to the next file as opposed
to exiting immediately. This allows for consistent behavior compared
to other common implementations of utilities such as cat(1) which
reduces potential confusion for the user.
Diffstat (limited to 'center.c')
-rw-r--r-- | center.c | 11 |
1 files changed, 7 insertions, 4 deletions
@@ -67,10 +67,13 @@ main(int argc, char **argv) center(stdin); else { FILE *fp; - if ((fp = fopen(*argv, "r")) == NULL) - errx(EXIT_FAILURE, "fopen"); - center(fp); - fclose(fp); + if ((fp = fopen(*argv, "r")) == NULL) { + warn("fopen"); + rval = EXIT_FAILURE; + } else { + center(fp); + fclose(fp); + } } } while (*++argv); |