Respect exit status in head(1)

This commit is contained in:
sin 2014-11-20 22:39:29 +00:00
parent 8767e4b320
commit 2a84dd5076

7
head.c
View File

@ -12,7 +12,7 @@ static void head(FILE *, const char *, long);
static void static void
usage(void) usage(void)
{ {
eprintf("usage: %s [-n] [FILE...]\n", argv0); eprintf("usage: %s [-n lines] [file...]\n", argv0);
} }
int int
@ -20,6 +20,7 @@ main(int argc, char *argv[])
{ {
long n = 10; long n = 10;
FILE *fp; FILE *fp;
int ret = 0;
ARGBEGIN { ARGBEGIN {
case 'n': case 'n':
@ -38,14 +39,14 @@ main(int argc, char *argv[])
for (; argc > 0; argc--, argv++) { for (; argc > 0; argc--, argv++) {
if (!(fp = fopen(argv[0], "r"))) { if (!(fp = fopen(argv[0], "r"))) {
weprintf("fopen %s:", argv[0]); weprintf("fopen %s:", argv[0]);
ret = 1;
continue; continue;
} }
head(fp, argv[0], n); head(fp, argv[0], n);
fclose(fp); fclose(fp);
} }
} }
return ret;
return 0;
} }
static void static void