diff options
author | Nathan Scott <nathans@sgi.com> | 2005-02-22 02:49:39 +0000 |
---|---|---|
committer | Nathan Scott <nathans@sgi.com> | 2005-02-22 02:49:39 +0000 |
commit | c9017cd8e22a9d70f5ba105fc7d03c3ed24d49b4 (patch) | |
tree | f6f6199262916dc1aaced5a3641a465da896e2a0 /setfattr | |
parent | 3af9ec3b25013fbec25e53693fa9fe37bff739ca (diff) | |
download | attr-c9017cd8e22a9d70f5ba105fc7d03c3ed24d49b4.tar.gz |
Updated next_line fix from AndreasG
Merge of master-melb:xfs-cmds:21594a by kenmcd.
Diffstat (limited to 'setfattr')
-rw-r--r-- | setfattr/setfattr.c | 51 |
1 files changed, 9 insertions, 42 deletions
diff --git a/setfattr/setfattr.c b/setfattr/setfattr.c index 6f5deaa..519d423 100644 --- a/setfattr/setfattr.c +++ b/setfattr/setfattr.c @@ -61,7 +61,6 @@ const char *progname; int do_set(const char *path, const char *name, const char *value); const char *decode(const char *value, size_t *size); int restore(const char *filename); -char *next_line(FILE *file); int hex_digit(char c); int base64_digit(char c); @@ -149,8 +148,15 @@ int restore(const char *filename) *value++ = '\0'; status = do_set(path, unquote(name), value); } - if (l != NULL) - line++; + if (l == NULL) + break; + line++; + } + if (!feof(file)) { + fprintf(stderr, "%s: %s: %s\n", progname, filename, + strerror(errno)); + if (!status) + status = 1; } cleanup: @@ -178,45 +184,6 @@ void help(void) " --help this help text\n")); } -char *next_line(FILE *file) -{ - 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[]) { int opt; |