diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2007-02-19 20:01:13 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2007-02-19 20:01:13 +0000 |
commit | fbc515e6584e89b4fc701399cf7b2b6937130266 (patch) | |
tree | 31ba07cacb9e9962b4c79c07b55a037e557ad1cf /usr.bin | |
parent | 30500acc82cecce626e7f1295956b30fa50491d5 (diff) |
- Check for fgets failure.
- Pass sizeof(buf) to fgets.
- Only print what was read.
- Simplify error checking while printing bigrams.
Inspired by diff from Charles Longeau <chl at tuxfamily dot org> long ago.
OK millert@ and moritz@.
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/locate/code/locate.code.c | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/usr.bin/locate/code/locate.code.c b/usr.bin/locate/code/locate.code.c index 88ff28a87d5..a6ea2bdacee 100644 --- a/usr.bin/locate/code/locate.code.c +++ b/usr.bin/locate/code/locate.code.c @@ -1,5 +1,5 @@ /* - * $OpenBSD: locate.code.c,v 1.13 2003/11/09 20:13:57 otto Exp $ + * $OpenBSD: locate.code.c,v 1.14 2007/02/19 20:01:12 ray Exp $ * * Copyright (c) 1989, 1993 * The Regents of the University of California. All rights reserved. @@ -31,7 +31,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: locate.code.c,v 1.13 2003/11/09 20:13:57 otto Exp $ + * $Id: locate.code.c,v 1.14 2007/02/19 20:01:12 ray Exp $ */ #ifndef lint @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)locate.code.c 8.1 (Berkeley) 6/6/93"; #else -static char rcsid[] = "$OpenBSD: locate.code.c,v 1.13 2003/11/09 20:13:57 otto Exp $"; +static char rcsid[] = "$OpenBSD: locate.code.c,v 1.14 2007/02/19 20:01:12 ray Exp $"; #endif #endif /* not lint */ @@ -146,9 +146,10 @@ main(int argc, char *argv[]) err(1, "%s", argv[0]); /* First copy bigram array to stdout. */ - (void)fgets(bigrams, BGBUFSIZE + 1, fp); + if (fgets(bigrams, sizeof(bigrams), fp) == NULL) + err(1, "fgets"); - if (fwrite(bigrams, 1, BGBUFSIZE, stdout) != BGBUFSIZE) + if (fputs(bigrams, stdout) == EOF) err(1, "stdout"); (void)fclose(fp); |