From ed106c3e0b7318bd55455e5f8df02f746b6216f5 Mon Sep 17 00:00:00 2001 From: Thomas Voss Date: Tue, 8 Feb 2022 00:49:51 +0100 Subject: 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. --- center.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'center.c') 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); -- cgit v1.2.3