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
This commit is contained in:
parent
7afc84396a
commit
d806f75cb6
2
README
2
README
|
@ -11,7 +11,7 @@ The following tools are implemented ('*' == finished, '#' == UTF-8 support,
|
||||||
------- -------------------- ---------------
|
------- -------------------- ---------------
|
||||||
=*| basename yes none
|
=*| basename yes none
|
||||||
=* cal yes none
|
=* cal yes none
|
||||||
=* cat yes none
|
=*| cat yes none
|
||||||
=* chgrp yes none
|
=* chgrp yes none
|
||||||
=* chmod yes none
|
=* chmod yes none
|
||||||
=* chown yes none
|
=* chown yes none
|
||||||
|
|
4
cat.1
4
cat.1
|
@ -1,4 +1,4 @@
|
||||||
.Dd January 16, 2015
|
.Dd March 1, 2015
|
||||||
.Dt CAT 1
|
.Dt CAT 1
|
||||||
.Os sbase
|
.Os sbase
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
|
@ -14,7 +14,7 @@ reads each
|
||||||
.Ar file
|
.Ar file
|
||||||
in sequence and writes it to stdout. If no
|
in sequence and writes it to stdout. If no
|
||||||
.Ar file
|
.Ar file
|
||||||
is given,
|
is given
|
||||||
.Nm
|
.Nm
|
||||||
reads from stdin.
|
reads from stdin.
|
||||||
.Sh OPTIONS
|
.Sh OPTIONS
|
||||||
|
|
17
cat.c
17
cat.c
|
@ -28,17 +28,18 @@ main(int argc, char *argv[])
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
concat(stdin, "<stdin>", stdout, "<stdout>");
|
concat(stdin, "<stdin>", stdout, "<stdout>");
|
||||||
} else {
|
} else {
|
||||||
for (; argc; argc--, argv++) {
|
for (; argc > 0; argc--, argv++) {
|
||||||
if (argv[0][0] == '-' && !argv[0][1])
|
if ((*argv)[0] == '-' && !(*argv)[1]) {
|
||||||
argv[0] = "/dev/fd/0";
|
concat(stdin, "<stdin>", stdout, "<stdout>");
|
||||||
if (!(fp = fopen(argv[0], "r"))) {
|
} else if (!(fp = fopen(*argv, "r"))) {
|
||||||
weprintf("fopen %s:", argv[0]);
|
weprintf("fopen %s:", *argv);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
continue;
|
} else {
|
||||||
}
|
concat(fp, *argv, stdout, "<stdout>");
|
||||||
concat(fp, argv[0], stdout, "<stdout>");
|
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user