diff options
| author | 2023-11-17 03:51:04 +0100 | |
|---|---|---|
| committer | 2023-11-17 03:51:04 +0100 | |
| commit | acf3cdcf80da7c3443e202a02d4b626c13e9e8dd (patch) | |
| tree | f9498dfd051d469d9e76c4b47c5704bfc9a79e48 /xs.h | |
| parent | Updated RELEASE_NOTES. (diff) | |
| download | penes-snac2-acf3cdcf80da7c3443e202a02d4b626c13e9e8dd.tar.gz penes-snac2-acf3cdcf80da7c3443e202a02d4b626c13e9e8dd.tar.xz penes-snac2-acf3cdcf80da7c3443e202a02d4b626c13e9e8dd.zip | |
Backport from xs.
Diffstat (limited to '')
| -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 | |||
| 1180 | 1180 | ||
| 1181 | /** hex **/ | 1181 | /** hex **/ |
| 1182 | 1182 | ||
| 1183 | static char xs_hex_digits[] = "0123456789abcdef"; | ||
| 1184 | |||
| 1183 | xs_str *xs_hex_enc(const xs_val *data, int size) | 1185 | xs_str *xs_hex_enc(const xs_val *data, int size) |
| 1184 | /* returns an hexdump of data */ | 1186 | /* returns an hexdump of data */ |
| 1185 | { | 1187 | { |
| @@ -1190,8 +1192,9 @@ xs_str *xs_hex_enc(const xs_val *data, int size) | |||
| 1190 | p = s = xs_realloc(NULL, _xs_blk_size(size * 2 + 1)); | 1192 | p = s = xs_realloc(NULL, _xs_blk_size(size * 2 + 1)); |
| 1191 | 1193 | ||
| 1192 | for (n = 0; n < size; n++) { | 1194 | for (n = 0; n < size; n++) { |
| 1193 | snprintf(p, 3, "%02x", (unsigned char)data[n]); | 1195 | *p++ = xs_hex_digits[*data >> 4 & 0xf]; |
| 1194 | p += 2; | 1196 | *p++ = xs_hex_digits[*data & 0xf]; |
| 1197 | data++; | ||
| 1195 | } | 1198 | } |
| 1196 | 1199 | ||
| 1197 | *p = '\0'; | 1200 | *p = '\0'; |