diff options
| author | Keith M Wesolowski <wesolows@foobazco.org> | 2014-10-15 14:16:29 +0000 |
|---|---|---|
| committer | Keith M Wesolowski <wesolows@foobazco.org> | 2014-10-15 14:16:29 +0000 |
| commit | bb95492e145eb3d24f2c5b4ac4b72d98bc0a4dee (patch) | |
| tree | cd4bb6f95ce12cc7fe0b940f36a6d4944c94f159 | |
| parent | 281135b6d6bac134f668ca9baae6d5939928d2be (diff) | |
| parent | 4e6070e87069f63bef94d8e79c2fc3cab2c1ab6b (diff) | |
| download | illumos-joyent-bb95492e145eb3d24f2c5b4ac4b72d98bc0a4dee.tar.gz | |
[illumos-gate merge]
commit 4e6070e87069f63bef94d8e79c2fc3cab2c1ab6b
5221 head shouldn't reuse stdin
| -rw-r--r-- | usr/src/cmd/head/head.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/usr/src/cmd/head/head.c b/usr/src/cmd/head/head.c index c08f2a450e..28e72d78f3 100644 --- a/usr/src/cmd/head/head.c +++ b/usr/src/cmd/head/head.c @@ -37,7 +37,7 @@ * contributors. */ /* - * Copyright (c) 2013, Joyent, Inc. All rights reserved. + * Copyright (c) 2014, Joyent, Inc. All rights reserved. */ @@ -52,6 +52,7 @@ static void copyout(off_t, int); static void Usage(); +static FILE *input; /* @@ -137,13 +138,16 @@ main(int argc, char **argv) break; if (argv[optind] != NULL) { - (void) close(0); - if (freopen(argv[optind], "r", stdin) == NULL) { + if (input != NULL) + (void) fclose(input); + if ((input = fopen(argv[optind], "r")) == NULL) { perror(argv[optind]); error = 1; optind++; continue; } + } else { + input = stdin; } if (quiet == 0) { @@ -172,7 +176,7 @@ copyout(off_t cnt, int isline) char lbuf[BUFSIZ]; size_t len; - while (cnt > 0 && fgets(lbuf, sizeof (lbuf), stdin) != 0) { + while (cnt > 0 && fgets(lbuf, sizeof (lbuf), input) != 0) { len = strlen(lbuf); if (isline) { (void) printf("%s", lbuf); |
