From: Karel Zak Date: Wed, 1 Nov 2017 14:33:04 +0000 (+0100) Subject: lib/mangle: return size of the decoded buffer X-Git-Tag: v2.32-rc1~242 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=61b9233995102d89e0f9d0beed6277071bb419ea;p=thirdparty%2Futil-linux.git lib/mangle: return size of the decoded buffer Signed-off-by: Karel Zak --- diff --git a/include/mangle.h b/include/mangle.h index ec492b5566..8c3888d919 100644 --- a/include/mangle.h +++ b/include/mangle.h @@ -8,7 +8,7 @@ extern char *mangle(const char *s); extern void unmangle_to_buffer(const char *s, char *buf, size_t len); -void unhexmangle_to_buffer(const char *s, char *buf, size_t len); +extern size_t unhexmangle_to_buffer(const char *s, char *buf, size_t len); extern char *unmangle(const char *s, char **end); diff --git a/lib/mangle.c b/lib/mangle.c index 354d3359fc..494360d7cb 100644 --- a/lib/mangle.c +++ b/lib/mangle.c @@ -70,12 +70,13 @@ void unmangle_to_buffer(const char *s, char *buf, size_t len) *buf = '\0'; } -void unhexmangle_to_buffer(const char *s, char *buf, size_t len) +size_t unhexmangle_to_buffer(const char *s, char *buf, size_t len) { size_t sz = 0; + const char *buf0 = buf; if (!s) - return; + return 0; while(*s && sz < len - 1) { if (*s == '\\' && sz + 3 < len - 1 && s[1] == 'x' && @@ -90,6 +91,7 @@ void unhexmangle_to_buffer(const char *s, char *buf, size_t len) } } *buf = '\0'; + return buf - buf0 + 1; } static inline char *skip_nonspaces(const char *s)