lib/mangle: return size of the decoded buffer

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2017-11-01 15:33:04 +01:00
parent da96496322
commit 61b9233995
2 changed files with 5 additions and 3 deletions

View File

@ -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);

View File

@ -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)