aboutsummaryrefslogtreecommitdiff
path: root/center.c
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2022-02-08 00:49:51 +0100
committerThomas Voss <mail@thomasvoss.com> 2022-02-08 00:49:51 +0100
commited106c3e0b7318bd55455e5f8df02f746b6216f5 (patch)
treeb1d7ea40aa35e6507da35888463a34211abeada0 /center.c
parenta3183ff88a1aaac66bd49f258fdd02fdeff421ca (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.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/center.c b/center.c
index ce0d50e..3192aa5 100644
--- a/center.c
+++ b/center.c
@@ -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);