Add "-" support to comm(1)

This commit is contained in:
sin 2014-11-13 15:38:39 +00:00
parent 49c91462b3
commit d208659414

4
comm.c
View File

@ -41,6 +41,8 @@ main(int argc, char *argv[])
usage(); usage();
for(i = 0; i < LEN(fp); i++) { for(i = 0; i < LEN(fp); i++) {
if (argv[i][0] == '-')
argv[i] = "/dev/fd/0";
if(!(fp[i] = fopen(argv[i], "r"))) if(!(fp[i] = fopen(argv[i], "r")))
eprintf("comm: '%s':", argv[i]); eprintf("comm: '%s':", argv[i]);
} }
@ -89,7 +91,6 @@ nextline(char *buf, int n, FILE *f, char *name)
eprintf("comm: '%s':", name); eprintf("comm: '%s':", name);
if(buf && !strchr(buf, '\n')) if(buf && !strchr(buf, '\n'))
eprintf("comm: '%s': line too long.\n", name); eprintf("comm: '%s': line too long.\n", name);
return buf; return buf;
} }
@ -100,6 +101,5 @@ finish(int pos, FILE *f, char *name)
while(nextline(buf, sizeof(buf), f, name)) while(nextline(buf, sizeof(buf), f, name))
printline(pos, buf); printline(pos, buf);
exit(1); exit(1);
} }