From 61b9233995102d89e0f9d0beed6277071bb419ea Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 1 Nov 2017 15:33:04 +0100 Subject: [PATCH] lib/mangle: return size of the decoded buffer Signed-off-by: Karel Zak --- include/mangle.h | 2 +- lib/mangle.c | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/include/mangle.h b/include/mangle.h index ec492b556..8c3888d91 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 354d3359f..494360d7c 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)