[hackers] [sbase] Audit cat(1) || FRIGN

From: <git_AT_suckless.org>
Date: Tue, 3 Mar 2015 14:32:25 +0100 (CET)

commit 18fb498e981b875dc523dae45ce29f05c676ee9f
Author: FRIGN <dev_AT_frign.de>
Date: Mon Mar 2 00:36:51 2015 +0100

    Audit cat(1)
    
    1) Fix usage ... spacing
    2) use *argv instead of argv[0] in the idiomatic for-loop
    3) Stop the na├»ve usage of "/dev/fd/0" and use plain stdin
       instead (This also makes error-messages more consistent).
    4) Add newline before return
    5) Remove comma in manpage

diff --git a/README b/README
index 95afd82..8f09017 100644
--- a/README
+++ b/README
_AT_@ -11,7 +11,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
     ------- -------------------- ---------------
 =*| basename yes none
 =* cal yes none
-=* cat yes none
+=*| cat yes none
 =* chgrp yes none
 =* chmod yes none
 =* chown yes none
diff --git a/cat.1 b/cat.1
index 60b304c..2332158 100644
--- a/cat.1
+++ b/cat.1
_AT_@ -1,4 +1,4 @@
-.Dd January 16, 2015
+.Dd March 1, 2015
 .Dt CAT 1
 .Os sbase
 .Sh NAME
_AT_@ -14,7 +14,7 @@ reads each
 .Ar file
 in sequence and writes it to stdout. If no
 .Ar file
-is given,
+is given
 .Nm
 reads from stdin.
 .Sh OPTIONS
diff --git a/cat.c b/cat.c
index 77131d1..90eefd5 100644
--- a/cat.c
+++ b/cat.c
_AT_@ -8,7 +8,7 @@
 static void
 usage(void)
 {
- eprintf("usage: %s [-u] [file...]\n", argv0);
+ eprintf("usage: %s [-u] [file ...]\n", argv0);
 }
 
 int
_AT_@ -28,17 +28,18 @@ main(int argc, char *argv[])
         if (argc == 0) {
                 concat(stdin, "<stdin>", stdout, "<stdout>");
         } else {
- for (; argc; argc--, argv++) {
- if (argv[0][0] == '-' && !argv[0][1])
- argv[0] = "/dev/fd/0";
- if (!(fp = fopen(argv[0], "r"))) {
- weprintf("fopen %s:", argv[0]);
+ for (; argc > 0; argc--, argv++) {
+ if ((*argv)[0] == '-' && !(*argv)[1]) {
+ concat(stdin, "<stdin>", stdout, "<stdout>");
+ } else if (!(fp = fopen(*argv, "r"))) {
+ weprintf("fopen %s:", *argv);
                                 ret = 1;
- continue;
+ } else {
+ concat(fp, *argv, stdout, "<stdout>");
+ fclose(fp);
                         }
- concat(fp, argv[0], stdout, "<stdout>");
- fclose(fp);
                 }
         }
+
         return ret;
 }
Received on Tue Mar 03 2015 - 14:32:25 CET

This archive was generated by hypermail 2.3.0 : Tue Mar 03 2015 - 14:36:16 CET