From: Ondrej Oprala Date: Mon, 23 Sep 2013 13:39:19 +0000 (+0200) Subject: hexdump: rewrite addfile() to use getline() X-Git-Tag: v2.25-rc1~761 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=96ea3d3200d9ed7f135d41815b312f11d086dc29;p=thirdparty%2Futil-linux.git hexdump: rewrite addfile() to use getline() Signed-off-by: Ondrej Oprala --- diff --git a/text-utils/parse.c b/text-utils/parse.c index 45052982e7..a6e5778252 100644 --- a/text-utils/parse.c +++ b/text-utils/parse.c @@ -57,25 +57,24 @@ void addfile(char *name) { char *p; FILE *fp; - int ch; - char buf[2048 + 1]; + size_t n; + char *buf = NULL; if ((fp = fopen(name, "r")) == NULL) err(EXIT_FAILURE, _("can't read %s"), name); - while (fgets(buf, sizeof(buf), fp)) { - if ((p = strchr(buf, '\n')) == NULL) { - warnx(_("line too long")); - while ((ch = getchar()) != '\n' && ch != EOF) - ; - continue; - } + + while (getline(&buf, &n, fp) != -1) { p = buf; + while (*p && isspace(*p)) ++p; if (!*p || *p == '#') continue; + add(p); } + + free(buf); fclose(fp); }