From d141df65f1b4ebb05f57d74b4afd1e8812f327d5 Mon Sep 17 00:00:00 2001 From: Nathan Scott Date: Tue, 29 Jul 2003 01:21:25 +0000 Subject: Little attr libmisc update from Andreas to ensure we dont exit from the library --- VERSION | 2 +- debian/changelog | 4 ++-- doc/CHANGES | 3 +++ getfattr/getfattr.c | 30 ++++++++++++++++++++---------- libmisc/quote.c | 8 ++------ libmisc/unquote.c | 2 -- setfattr/setfattr.c | 12 +++++++++++- 7 files changed, 39 insertions(+), 22 deletions(-) diff --git a/VERSION b/VERSION index ffa0cc7..678f35b 100644 --- a/VERSION +++ b/VERSION @@ -3,5 +3,5 @@ # PKG_MAJOR=2 PKG_MINOR=4 -PKG_REVISION=6 +PKG_REVISION=7 PKG_BUILD=0 diff --git a/debian/changelog b/debian/changelog index 437e172..c36e6ee 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,8 +1,8 @@ -attr (2.4.6-1) unstable; urgency=low +attr (2.4.7-1) unstable; urgency=low * New upstream release - -- Nathan Scott Mon, 21 Jul 2003 13:38:45 +1000 + -- Nathan Scott Tue, 29 Jul 2003 11:09:50 +1000 attr (2.4.5-1) unstable; urgency=low diff --git a/doc/CHANGES b/doc/CHANGES index f49d129..21d1912 100644 --- a/doc/CHANGES +++ b/doc/CHANGES @@ -1,3 +1,6 @@ +attr-2.4.7 (29 July 2003) + - Make quote return NULL if out of memory instead of exiting. + attr-2.4.6 (21 July 2003) - Add internal library for misc. functions: quote, unquote, high_water_alloc. diff --git a/getfattr/getfattr.c b/getfattr/getfattr.c index 0b3bd31..e8ed902 100644 --- a/getfattr/getfattr.c +++ b/getfattr/getfattr.c @@ -71,6 +71,16 @@ int had_errors; regex_t name_regex; +static const char *xquote(const char *str) +{ + const char *q = quote(str); + if (q == NULL) { + fprintf(stderr, "%s: %s\n", progname, strerror(errno)); + exit(1); + } + return q; +} + int do_getxattr(const char *path, const char *name, void *value, size_t size) { return (opt_deref ? getxattr : lgetxattr)(path, name, value, size); @@ -218,8 +228,8 @@ int print_attribute(const char *path, const char *name, int *header_printed) if (opt_dump || opt_value_only) { length = do_getxattr(path, name, NULL, 0); if (length < 0) { - fprintf(stderr, "%s: ", quote(path)); - fprintf(stderr, "%s: %s\n", quote(name), + fprintf(stderr, "%s: ", xquote(path)); + fprintf(stderr, "%s: %s\n", xquote(name), strerror_ea(errno)); return 1; } @@ -230,8 +240,8 @@ int print_attribute(const char *path, const char *name, int *header_printed) } length = do_getxattr(path, name, value, value_size); if (length < 0) { - fprintf(stderr, "%s: ", quote(path)); - fprintf(stderr, "%s: %s\n", quote(name), + fprintf(stderr, "%s: ", xquote(path)); + fprintf(stderr, "%s: %s\n", xquote(name), strerror_ea(errno)); return 1; } @@ -255,7 +265,7 @@ int print_attribute(const char *path, const char *name, int *header_printed) } if (!*header_printed && !opt_value_only) { - printf("# file: %s\n", quote(path)); + printf("# file: %s\n", xquote(path)); *header_printed = 1; } @@ -265,9 +275,9 @@ int print_attribute(const char *path, const char *name, int *header_printed) const char *enc = encode(value, &length); if (enc) - printf("%s=%s\n", quote(name), enc); + printf("%s=%s\n", xquote(name), enc); } else - puts(quote(name)); + puts(xquote(name)); return 0; } @@ -284,7 +294,7 @@ int list_attributes(const char *path, int *header_printed) length = do_listxattr(path, NULL, 0); if (length < 0) { - fprintf(stderr, "%s: %s: %s\n", progname, quote(path), + fprintf(stderr, "%s: %s: %s\n", progname, xquote(path), strerror_ea(errno)); had_errors++; return 1; @@ -299,7 +309,7 @@ int list_attributes(const char *path, int *header_printed) length = do_listxattr(path, list, list_size); if (length < 0) { - perror(quote(path)); + perror(xquote(path)); had_errors++; return 1; } @@ -341,7 +351,7 @@ int do_print(const char *path, const struct stat *stat, if (flag & FTW_DNR) { /* Item is a directory which can't be read. */ - fprintf(stderr, "%s: %s: %s\n", progname, quote(path), + fprintf(stderr, "%s: %s: %s\n", progname, xquote(path), strerror(errno)); return 0; } diff --git a/libmisc/quote.c b/libmisc/quote.c index e5737e7..633f941 100644 --- a/libmisc/quote.c +++ b/libmisc/quote.c @@ -23,8 +23,6 @@ #include #include "misc.h" -extern const char *progname; - const char *quote(const char *str) { static char *quoted_str; @@ -40,10 +38,8 @@ const char *quote(const char *str) return str; if (high_water_alloc((void **)"ed_str, "ed_str_len, - nonpr * 3 + 1)) { - perror(progname); - exit(1); - } + nonpr * 3 + 1)) + return NULL; for (s = (unsigned char *)str, q = quoted_str; *s != '\0'; s++) { if (!isprint(*s) || isspace(*s) || *s == '\\') { *q++ = '\\'; diff --git a/libmisc/unquote.c b/libmisc/unquote.c index 5444b65..a3bf6fe 100644 --- a/libmisc/unquote.c +++ b/libmisc/unquote.c @@ -23,8 +23,6 @@ #include #include "misc.h" -extern const char *progname; - char *unquote(char *str) { unsigned char *s, *t; diff --git a/setfattr/setfattr.c b/setfattr/setfattr.c index d9d1ad2..21b02ee 100644 --- a/setfattr/setfattr.c +++ b/setfattr/setfattr.c @@ -70,6 +70,16 @@ const char *strerror_ea(int err) return strerror(err); } +static const char *xquote(const char *str) +{ + const char *q = quote(str); + if (q == NULL) { + fprintf(stderr, "%s: %s\n", progname, strerror(errno)); + exit(1); + } + return q; +} + int do_setxattr(const char *path, const char *name, const void *value, size_t size) { @@ -270,7 +280,7 @@ int do_set(const char *path, const char *name, const char *value) if (error < 0) { fprintf(stderr, "%s: %s: %s\n", - progname, quote(path), strerror_ea(errno)); + progname, xquote(path), strerror_ea(errno)); had_errors++; return 1; } -- cgit v1.2.3