-static size_t hex_to_bytes(const char *hex, char **result)
-{
- char buf[3] = "xx\0", *endp, *bytes;
- size_t i, len;
-
- len = strlen(hex);
- if (len % 2)
- return -EINVAL;
- len /= 2;
-
- if (!(bytes = malloc(len)))
- return -ENOMEM;
-
- for (i = 0; i < len; i++) {
- memcpy(buf, &hex[i * 2], 2);
- bytes[i] = strtoul(buf, &endp, 16);
- if (endp != &buf[2]) {
- free(bytes);
- return -EINVAL;
- }
- }
- *result = bytes;
- return i;
-}
-