summaryrefslogtreecommitdiff
path: root/setfattr/setfattr.c
diff options
context:
space:
mode:
Diffstat (limited to 'setfattr/setfattr.c')
-rw-r--r--setfattr/setfattr.c46
1 files changed, 35 insertions, 11 deletions
diff --git a/setfattr/setfattr.c b/setfattr/setfattr.c
index 6cf8700..6f5deaa 100644
--- a/setfattr/setfattr.c
+++ b/setfattr/setfattr.c
@@ -180,17 +180,41 @@ void help(void)
char *next_line(FILE *file)
{
- static char line[PATH_MAX+32], *c;
- if (!fgets(line, sizeof(line), file))
- return NULL;
-
- c = strrchr(line, '\0');
- while (c > line && (*(c-1) == '\n' ||
- *(c-1) == '\r')) {
- c--;
- *c = '\0';
- }
- return line;
+ static char *line;
+ static size_t line_size;
+ char *c;
+ int eol = 0;
+
+ if (!line) {
+ if (high_water_alloc((void **)&line, &line_size, PATH_MAX)) {
+ perror(progname);
+ had_errors++;
+ return NULL;
+ }
+ }
+ c = line;
+ do {
+ if (!fgets(c, line_size - (c - line), file))
+ return NULL;
+ c = strrchr(c, '\0');
+ while (c > line && (*(c-1) == '\n' || *(c-1) == '\r')) {
+ c--;
+ *c = '\0';
+ eol = 1;
+ }
+ if (feof(file))
+ break;
+ if (!eol) {
+ if (high_water_alloc((void **)&line, &line_size,
+ 2 * line_size)) {
+ perror(progname);
+ had_errors++;
+ return NULL;
+ }
+ c = strrchr(line, '\0');
+ }
+ } while (!eol);
+ return line;
}
int main(int argc, char *argv[])