diff options
author | Aaron Campbell <aaron@cvs.openbsd.org> | 1999-02-07 20:54:10 +0000 |
---|---|---|
committer | Aaron Campbell <aaron@cvs.openbsd.org> | 1999-02-07 20:54:10 +0000 |
commit | 6e125f58b2f1bad737b8a842fc3ec56512a6689c (patch) | |
tree | ed317b2ba4922cfa602eda44303c12e4fe7090a8 /usr.bin/hexdump/parse.c | |
parent | 06ac1d9ab4fd2b4b6a62e7240bf092e9bc270161 (diff) |
fgets -> fgetln, don't lie about lines being too long
Diffstat (limited to 'usr.bin/hexdump/parse.c')
-rw-r--r-- | usr.bin/hexdump/parse.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/usr.bin/hexdump/parse.c b/usr.bin/hexdump/parse.c index 679711e5cea..7422db9ee4f 100644 --- a/usr.bin/hexdump/parse.c +++ b/usr.bin/hexdump/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.4 1998/08/11 22:06:27 provos Exp $ */ +/* $OpenBSD: parse.c,v 1.5 1999/02/07 20:54:09 aaron Exp $ */ /* * Copyright (c) 1989 The Regents of the University of California. @@ -35,7 +35,7 @@ #ifndef lint /*static char sccsid[] = "from: @(#)parse.c 5.6 (Berkeley) 3/9/91";*/ -static char rcsid[] = "$OpenBSD: parse.c,v 1.4 1998/08/11 22:06:27 provos Exp $"; +static char rcsid[] = "$OpenBSD: parse.c,v 1.5 1999/02/07 20:54:09 aaron Exp $"; #endif /* not lint */ #include <sys/types.h> @@ -53,21 +53,20 @@ addfile(name) { register char *p; FILE *fp; - int ch; - char buf[2048 + 1]; + size_t len; if (!(fp = fopen(name, "r"))) { (void)fprintf(stderr, "hexdump: can't read %s.\n", name); exit(1); } - while (fgets(buf, sizeof(buf), fp)) { - if (!(p = strchr(buf, '\n'))) { - (void)fprintf(stderr, "hexdump: line too long.\n"); - while ((ch = getchar()) != '\n' && ch != EOF); + while ((p = fgetln(fp, &len))) { + if (*(p + len - 1) == '\n') + *(p + len - 1) = '\0'; + else { + (void)fprintf(stderr, "hexdump: incomplete line.\n"); continue; } - *p = '\0'; - for (p = buf; *p && isspace(*p); ++p); + for (; *p && isspace(*p); ++p); if (!*p || *p == '#') continue; add(p); |