diff options
author | Nathan Scott <nathans@sgi.com> | 2005-02-21 02:48:17 +0000 |
---|---|---|
committer | Nathan Scott <nathans@sgi.com> | 2005-02-21 02:48:17 +0000 |
commit | e6c9beae775453548abf0d0481bde6fc8ad3a079 (patch) | |
tree | 20b29fedc0fdf54cff3bf8ba9542b4f136d887ac /setfacl | |
parent | c77f0c9a6e5c27c21f7f1ea2958354a4c66a7ee2 (diff) | |
download | acl-e6c9beae775453548abf0d0481bde6fc8ad3a079.tar.gz |
setfacl line buffer allocation fix from AndreasG.
Merge of master-melb:xfs-cmds:21574a by kenmcd.
Diffstat (limited to 'setfacl')
-rw-r--r-- | setfacl/setfacl.c | 49 |
1 files changed, 36 insertions, 13 deletions
diff --git a/setfacl/setfacl.c b/setfacl/setfacl.c index 20cea05..67ad145 100644 --- a/setfacl/setfacl.c +++ b/setfacl/setfacl.c @@ -275,25 +275,48 @@ void help(void) } +static int __errors; +static seq_t __seq; + char *next_line(FILE *file) { - static char line[PATH_MAX], *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'; + 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); + __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); + __errors++; + return NULL; + } + c = strrchr(line, '\0'); + } + } while (!eol); return line; } - - -static int __errors; -static seq_t __seq; int __do_set(const char *file, const struct stat *stat, int flag, struct FTW *ftw) { |