summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--getfattr/getfattr.c28
-rw-r--r--setfattr/setfattr.c6
2 files changed, 17 insertions, 17 deletions
diff --git a/getfattr/getfattr.c b/getfattr/getfattr.c
index 5ec7f00..cae9c3f 100644
--- a/getfattr/getfattr.c
+++ b/getfattr/getfattr.c
@@ -67,9 +67,9 @@ int had_errors;
regex_t name_regex;
-static const char *xquote(const char *str)
+static const char *xquote(const char *str, const char *quote_chars)
{
- const char *q = quote(str);
+ const char *q = quote(str, quote_chars);
if (q == NULL) {
fprintf(stderr, "%s: %s\n", progname, strerror(errno));
exit(1);
@@ -133,7 +133,7 @@ const char *encode(const char *value, size_t *size)
size_t n, extra = 0;
for (e=(char *)value; e < value + *size; e++) {
- if (!isprint(*e))
+ if (*e == '\n' || *e == '\r')
extra += 4;
else if (*e == '\\' || *e == '"')
extra++;
@@ -147,7 +147,7 @@ const char *encode(const char *value, size_t *size)
e = encoded;
*e++='"';
for (n = 0; n < *size; n++, value++) {
- if (!isprint(*value)) {
+ if (*value == '\n' || *value == '\r') {
*e++ = '\\';
*e++ = '0' + ((unsigned char)*value >> 6);
*e++ = '0' + (((unsigned char)*value & 070) >> 3);
@@ -230,8 +230,8 @@ int print_attribute(const char *path, const char *name, int *header_printed)
if (opt_dump || opt_value_only) {
rval = do_getxattr(path, name, NULL, 0);
if (rval < 0) {
- fprintf(stderr, "%s: ", xquote(path));
- fprintf(stderr, "%s: %s\n", xquote(name),
+ fprintf(stderr, "%s: ", xquote(path, "\n\r"));
+ fprintf(stderr, "%s: %s\n", xquote(name, "\n\r"),
strerror_ea(errno));
return 1;
}
@@ -242,8 +242,8 @@ int print_attribute(const char *path, const char *name, int *header_printed)
}
rval = do_getxattr(path, name, value, value_size);
if (rval < 0) {
- fprintf(stderr, "%s: ", xquote(path));
- fprintf(stderr, "%s: %s\n", xquote(name),
+ fprintf(stderr, "%s: ", xquote(path, "\n\r"));
+ fprintf(stderr, "%s: %s\n", xquote(name, "\n\r"),
strerror_ea(errno));
return 1;
}
@@ -268,7 +268,7 @@ int print_attribute(const char *path, const char *name, int *header_printed)
}
if (!*header_printed && !opt_value_only) {
- printf("# file: %s\n", xquote(path));
+ printf("# file: %s\n", xquote(path, "\n\r"));
*header_printed = 1;
}
@@ -278,9 +278,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", xquote(name), enc);
+ printf("%s=%s\n", xquote(name, "=\n\r"), enc);
} else
- puts(xquote(name));
+ puts(xquote(name, "=\n\r"));
return 0;
}
@@ -297,7 +297,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, xquote(path),
+ fprintf(stderr, "%s: %s: %s\n", progname, xquote(path, "\n\r"),
strerror_ea(errno));
had_errors++;
return 1;
@@ -312,7 +312,7 @@ int list_attributes(const char *path, int *header_printed)
length = do_listxattr(path, list, list_size);
if (length < 0) {
- perror(xquote(path));
+ perror(xquote(path, "\n\r"));
had_errors++;
return 1;
}
@@ -353,7 +353,7 @@ int do_print(const char *path, const struct stat *stat, int walk_flags,
int header_printed = 0;
if (walk_flags & WALK_TREE_FAILED) {
- fprintf(stderr, "%s: %s: %s\n", progname, xquote(path),
+ fprintf(stderr, "%s: %s: %s\n", progname, xquote(path, "\n\r"),
strerror(errno));
return 1;
}
diff --git a/setfattr/setfattr.c b/setfattr/setfattr.c
index 0fe1927..491c25a 100644
--- a/setfattr/setfattr.c
+++ b/setfattr/setfattr.c
@@ -72,9 +72,9 @@ const char *strerror_ea(int err)
return strerror(err);
}
-static const char *xquote(const char *str)
+static const char *xquote(const char *str, const char *quote_chars)
{
- const char *q = quote(str);
+ const char *q = quote(str, quote_chars);
if (q == NULL) {
fprintf(stderr, "%s: %s\n", progname, strerror(errno));
exit(1);
@@ -276,7 +276,7 @@ int do_set(const char *path, const char *name, const char *value)
if (error < 0) {
fprintf(stderr, "%s: %s: %s\n",
- progname, xquote(path), strerror_ea(errno));
+ progname, xquote(path, "\n\r"), strerror_ea(errno));
had_errors++;
return 1;
}