Modify argv[0] in place

This commit is contained in:
sin 2014-11-13 15:24:43 +00:00
parent 6449db8691
commit 7ffe164106

10
cat.c
View File

@ -15,7 +15,6 @@ usage(void)
int
main(int argc, char *argv[])
{
char *p;
FILE *fp;
int ret = 0;
@ -31,15 +30,14 @@ main(int argc, char *argv[])
concat(stdin, "<stdin>", stdout, "<stdout>");
} else {
for (; argc; argc--, argv++) {
p = argv[0];
if (argv[0][0] == '-')
p = "/dev/fd/0";
if(!(fp = fopen(p, "r"))) {
weprintf("fopen %s:", p);
argv[0] = "/dev/fd/0";
if(!(fp = fopen(argv[0], "r"))) {
weprintf("fopen %s:", argv[0]);
ret = 1;
continue;
}
concat(fp, p, stdout, "<stdout>");
concat(fp, argv[0], stdout, "<stdout>");
fclose(fp);
}
}