]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
hexdump: rewrite addfile() to use getline()
authorOndrej Oprala <ooprala@redhat.com>
Mon, 23 Sep 2013 13:39:19 +0000 (15:39 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 8 Nov 2013 11:54:52 +0000 (12:54 +0100)
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
text-utils/parse.c

index 45052982e7dd798110f98790d6102c5a6e19c0f6..a6e5778252d025989e96142d02662ea09f999947 100644 (file)
@@ -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);
 }