diff options
author | default <nobody@localhost> | 2023-11-17 03:51:04 +0100 |
---|---|---|
committer | default <nobody@localhost> | 2023-11-17 03:51:04 +0100 |
commit | acf3cdcf80da7c3443e202a02d4b626c13e9e8dd (patch) | |
tree | f9498dfd051d469d9e76c4b47c5704bfc9a79e48 /xs.h | |
parent | 57ab8df0076ba8d57dce16fdd3a5e38c744e1a04 (diff) |
Backport from xs.
Diffstat (limited to 'xs.h')
-rw-r--r-- | xs.h | 7 |
1 files changed, 5 insertions, 2 deletions
@@ -1180,6 +1180,8 @@ void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size /** hex **/ +static char xs_hex_digits[] = "0123456789abcdef"; + xs_str *xs_hex_enc(const xs_val *data, int size) /* returns an hexdump of data */ { @@ -1190,8 +1192,9 @@ xs_str *xs_hex_enc(const xs_val *data, int size) p = s = xs_realloc(NULL, _xs_blk_size(size * 2 + 1)); for (n = 0; n < size; n++) { - snprintf(p, 3, "%02x", (unsigned char)data[n]); - p += 2; + *p++ = xs_hex_digits[*data >> 4 & 0xf]; + *p++ = xs_hex_digits[*data & 0xf]; + data++; } *p = '\0'; |