hexdump: rewrite addfile() to use getline()
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
This commit is contained in:
parent
d6e5614e5d
commit
96ea3d3200
|
@ -57,25 +57,24 @@ void addfile(char *name)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int ch;
|
size_t n;
|
||||||
char buf[2048 + 1];
|
char *buf = NULL;
|
||||||
|
|
||||||
if ((fp = fopen(name, "r")) == NULL)
|
if ((fp = fopen(name, "r")) == NULL)
|
||||||
err(EXIT_FAILURE, _("can't read %s"), name);
|
err(EXIT_FAILURE, _("can't read %s"), name);
|
||||||
while (fgets(buf, sizeof(buf), fp)) {
|
|
||||||
if ((p = strchr(buf, '\n')) == NULL) {
|
while (getline(&buf, &n, fp) != -1) {
|
||||||
warnx(_("line too long"));
|
|
||||||
while ((ch = getchar()) != '\n' && ch != EOF)
|
|
||||||
;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
p = buf;
|
p = buf;
|
||||||
|
|
||||||
while (*p && isspace(*p))
|
while (*p && isspace(*p))
|
||||||
++p;
|
++p;
|
||||||
if (!*p || *p == '#')
|
if (!*p || *p == '#')
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
add(p);
|
add(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(buf);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue