diff options
| author | Robert Mustacchi <rm@joyent.com> | 2014-10-08 15:00:22 -0700 |
|---|---|---|
| committer | Robert Mustacchi <rm@joyent.com> | 2014-10-15 06:26:54 -0700 |
| commit | 4e6070e87069f63bef94d8e79c2fc3cab2c1ab6b (patch) | |
| tree | 083855dd7fe3b029e72ea010be01e3244822bdb8 /usr/src/cmd/head | |
| parent | 45405cce0657d01714b3d014a0facf3bdce45736 (diff) | |
| download | illumos-joyent-4e6070e87069f63bef94d8e79c2fc3cab2c1ab6b.tar.gz | |
5221 head shouldn't reuse stdin
Reviewed by: Dan McDonald <danmcd@omniti.com>
Reviewed by: Patrick Domack <patrickdk@patrickdk.com>
Approved by: Gordon Ross <gwr@nexenta.com>
Diffstat (limited to 'usr/src/cmd/head')
| -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); |
