Modify argv[0] in place
This commit is contained in:
parent
6449db8691
commit
7ffe164106
10
cat.c
10
cat.c
@ -15,7 +15,6 @@ usage(void)
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char *p;
|
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
@ -31,15 +30,14 @@ main(int argc, char *argv[])
|
|||||||
concat(stdin, "<stdin>", stdout, "<stdout>");
|
concat(stdin, "<stdin>", stdout, "<stdout>");
|
||||||
} else {
|
} else {
|
||||||
for (; argc; argc--, argv++) {
|
for (; argc; argc--, argv++) {
|
||||||
p = argv[0];
|
|
||||||
if (argv[0][0] == '-')
|
if (argv[0][0] == '-')
|
||||||
p = "/dev/fd/0";
|
argv[0] = "/dev/fd/0";
|
||||||
if(!(fp = fopen(p, "r"))) {
|
if(!(fp = fopen(argv[0], "r"))) {
|
||||||
weprintf("fopen %s:", p);
|
weprintf("fopen %s:", argv[0]);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
concat(fp, p, stdout, "<stdout>");
|
concat(fp, argv[0], stdout, "<stdout>");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user