]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib/mangle: return size of the decoded buffer
authorKarel Zak <kzak@redhat.com>
Wed, 1 Nov 2017 14:33:04 +0000 (15:33 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 1 Nov 2017 14:33:04 +0000 (15:33 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/mangle.h
lib/mangle.c

index ec492b5566afd2f4401057669f57b58e869fb6fc..8c3888d9191d93218be41a30233087aed102c53c 100644 (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);
 
index 354d3359fcc7701c55b040e422f92a3d9646e946..494360d7cbee238457e996edd7a52cf0bbd3a199 100644 (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)