summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Gruenbacher <agruen@suse.de>2009-06-22 20:03:16 +0200
committerAndreas Gruenbacher <agruen@suse.de>2009-06-22 20:46:54 +0200
commit6fab4d7598d0be4908e54d469171a1715e57cda2 (patch)
treef6999db84d02e423005821383368783e5bad2cfc
parentcb44d79564db216af18d9beb632700e40634f166 (diff)
downloadattr-6fab4d7598d0be4908e54d469171a1715e57cda2.tar.gz
Add a parameter to quote() to specify which characters to quote
-rw-r--r--include/misc.h2
-rw-r--r--libmisc/quote.c6
2 files changed, 4 insertions, 4 deletions
diff --git a/include/misc.h b/include/misc.h
index 58c2640..0c5fdcc 100644
--- a/include/misc.h
+++ b/include/misc.h
@@ -17,7 +17,7 @@
extern int high_water_alloc(void **buf, size_t *bufsize, size_t newsize);
-extern const char *quote(const char *str);
+extern const char *quote(const char *str, const char *quote_chars);
extern char *unquote(char *str);
extern char *next_line(FILE *file);
diff --git a/libmisc/quote.c b/libmisc/quote.c
index 4fb7035..f98c887 100644
--- a/libmisc/quote.c
+++ b/libmisc/quote.c
@@ -22,7 +22,7 @@
#include <ctype.h>
#include "misc.h"
-const char *quote(const char *str)
+const char *quote(const char *str, const char *quote_chars)
{
static char *quoted_str;
static size_t quoted_str_len;
@@ -34,7 +34,7 @@ const char *quote(const char *str)
return str;
for (nonpr = 0, s = (unsigned char *)str; *s != '\0'; s++)
- if (!isprint(*s) || isspace(*s) || *s == '\\' || *s == '=')
+ if (*s == '\\' || strchr(quote_chars, *s))
nonpr++;
if (nonpr == 0)
return str;
@@ -43,7 +43,7 @@ const char *quote(const char *str)
(s - (unsigned char *)str) + nonpr * 3 + 1))
return NULL;
for (s = (unsigned char *)str, q = quoted_str; *s != '\0'; s++) {
- if (!isprint(*s) || isspace(*s) || *s == '\\' || *s == '=') {
+ if (*s == '\\' || strchr(quote_chars, *s)) {
*q++ = '\\';
*q++ = '0' + ((*s >> 6) );
*q++ = '0' + ((*s >> 3) & 7);