Commit 38346b3e authored by Geoff Simmons's avatar Geoff Simmons

tweak hex_decode some more, so that it's now all inlined

parent 1b2e9060
......@@ -54,35 +54,6 @@ static const uint8_t nibble[] = {
11, 12, 13, 14, 15
};
static inline int
isxstr(const char * const p, ssize_t *l)
{
const char *s = p;
while (*s)
if (!isxdigit(*s++))
return 0;
else
*l += 1;
return 1;
}
static inline ssize_t
check(const char * const p, va_list ap)
{
ssize_t len = 0;
va_list ap2;
va_copy(ap2, ap);
for (const char *s = p; s != vrt_magic_string_end;
s = va_arg(ap2, const char *))
if (s != NULL && *s != '\0' && !isxstr(s, &len)) {
len = -1;
break;
}
va_end(ap2);
return len;
}
static inline char
hex2byte(const unsigned char hi, const unsigned char lo)
{
......@@ -121,15 +92,29 @@ hex_decode(const enum encoding dec, char *restrict const buf,
{
char *dest = buf;
unsigned char extranib = 0;
ssize_t len;
ssize_t len = 0;
va_list ap2;
AN(buf);
assert(dec == HEX);
if (p == vrt_magic_string_end)
return 0;
va_copy(ap2, ap);
for (const char *s = p; s != vrt_magic_string_end;
s = va_arg(ap2, const char *)) {
const char *b = s;
if (s != NULL)
while (*s)
if (!isxdigit(*s++)) {
len = -1;
break;
}
if (len == -1)
break;
len += s - b;
}
va_end(ap2);
if ((len = check(p, ap)) == 0)
if (len == 0)
return 0;
if (len == -1) {
errno = EINVAL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment