[hackers] [sbase] Don't exit on the first file that can't be opened for head and fold || sin

From: <git_AT_suckless.org>
Date: Tue, 12 Nov 2013 11:47:19 +0100

commit d9abff1e84d0c1ea41cfa2305502cb3d0a76ba34
Author: sin <sin_AT_2f30.org>
Date: Tue Nov 12 10:44:37 2013 +0000

    Don't exit on the first file that can't be opened for head and fold

diff --git a/fold.c b/fold.c
index d327c62..4dfaf11 100644
--- a/fold.c
+++ b/fold.c
_AT_@ -1,8 +1,10 @@
 /* See LICENSE file for copyright and license details. */
 #include <ctype.h>
+#include <errno.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include "text.h"
 #include "util.h"
_AT_@ -45,8 +47,11 @@ main(int argc, char *argv[])
         if(argc == 0) {
                 fold(stdin, width);
         } else for(; argc > 0; argc--, argv++) {
- if(!(fp = fopen(argv[0], "r")))
- eprintf("fopen %s:", argv[0]);
+ if(!(fp = fopen(argv[0], "r"))) {
+ fprintf(stderr, "fopen %s: %s
", argv[0],
+ strerror(errno));
+ continue;
+ }
                 fold(fp, width);
                 fclose(fp);
         }
diff --git a/head.c b/head.c
index 8011151..6578f89 100644
--- a/head.c
+++ b/head.c
_AT_@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
_AT_@ -33,8 +34,11 @@ main(int argc, char *argv[])
         if(argc == 0) {
                 head(stdin, "<stdin>", n);
         } else for(; argc > 0; argc--, argv++) {
- if(!(fp = fopen(argv[0], "r")))
- eprintf("fopen %s:", argv[0]);
+ if(!(fp = fopen(argv[0], "r"))) {
+ fprintf(stderr, "fopen %s: %s
", argv[0],
+ strerror(errno));
+ continue;
+ }
                 head(fp, argv[0], n);
                 fclose(fp);
         }
Received on Tue Nov 12 2013 - 11:47:19 CET

This archive was generated by hypermail 2.3.0 : Tue Nov 12 2013 - 11:48:14 CET