diff options
author | Ondrej Oprala | 2013-09-23 15:39:19 +0200 |
---|---|---|
committer | Karel Zak | 2013-11-08 12:54:52 +0100 |
commit | 96ea3d3200d9ed7f135d41815b312f11d086dc29 (patch) | |
tree | cf1aef079c1792ed355495ff3b20fa25968e1086 /text-utils/parse.c | |
parent | hexdump: formatting and variable name cleanup (diff) | |
download | kernel-qcow2-util-linux-96ea3d3200d9ed7f135d41815b312f11d086dc29.tar.gz kernel-qcow2-util-linux-96ea3d3200d9ed7f135d41815b312f11d086dc29.tar.xz kernel-qcow2-util-linux-96ea3d3200d9ed7f135d41815b312f11d086dc29.zip |
hexdump: rewrite addfile() to use getline()
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
Diffstat (limited to 'text-utils/parse.c')
-rw-r--r-- | text-utils/parse.c | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/text-utils/parse.c b/text-utils/parse.c index 45052982e..a6e577825 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); } |