From 6febfd0d4bdf7519e119149b8d8ec03c210aed1d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 7 Jul 2010 20:58:02 +0200 Subject: [PATCH] util: introduce cunescape_length() --- src/util.c | 9 ++++++--- src/util.h | 11 ++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/util.c b/src/util.c index 58b96aec..5103cc6c 100644 --- a/src/util.c +++ b/src/util.c @@ -1129,7 +1129,7 @@ char *cescape(const char *s) { return r; } -char *cunescape(const char *s) { +char *cunescape_length(const char *s, size_t length) { char *r, *t; const char *f; @@ -1137,10 +1137,10 @@ char *cunescape(const char *s) { /* Undoes C style string escaping */ - if (!(r = new(char, strlen(s)+1))) + if (!(r = new(char, length+1))) return r; - for (f = s, t = r; *f; f++) { + for (f = s, t = r; f < s + length; f++) { if (*f != '\\') { *(t++) = *f; @@ -1242,6 +1242,9 @@ finish: return r; } +char *cunescape(const char *s) { + return cunescape_length(s, strlen(s)); +} char *xescape(const char *s, const char *bad) { char *r, *t; diff --git a/src/util.h b/src/util.h index fed0e670..ff79583d 100644 --- a/src/util.h +++ b/src/util.h @@ -222,6 +222,12 @@ int undecchar(char c); char *cescape(const char *s); char *cunescape(const char *s); +char *cunescape_length(const char *s, size_t length); + +char *xescape(const char *s, const char *bad); + +char *bus_path_escape(const char *s); +char *bus_path_unescape(const char *s); char *path_kill_slashes(char *path); @@ -230,11 +236,6 @@ bool path_equal(const char *a, const char *b); char *ascii_strlower(char *path); -char *xescape(const char *s, const char *bad); - -char *bus_path_escape(const char *s); -char *bus_path_unescape(const char *s); - bool ignore_file(const char *filename); bool chars_intersect(const char *a, const char *b); -- 2.39.5