summaryrefslogtreecommitdiff
path: root/xs.h
diff options
context:
space:
mode:
authorGravatar default2023-11-17 08:51:53 +0100
committerGravatar default2023-11-17 08:51:53 +0100
commit80c5bac826c480fdabfaeae991a9a7fb298fb865 (patch)
tree3dcc249478b68120aeb9cbdd0d9ba442463314dd /xs.h
parentBackport from xs. (diff)
downloadpenes-snac2-80c5bac826c480fdabfaeae991a9a7fb298fb865.tar.gz
penes-snac2-80c5bac826c480fdabfaeae991a9a7fb298fb865.tar.xz
penes-snac2-80c5bac826c480fdabfaeae991a9a7fb298fb865.zip
Backport from xs.
Diffstat (limited to 'xs.h')
-rw-r--r--xs.h73
1 files changed, 0 insertions, 73 deletions
diff --git a/xs.h b/xs.h
index c0857bc..63715ac 100644
--- a/xs.h
+++ b/xs.h
@@ -119,10 +119,6 @@ void xs_data_get(void *data, const xs_data *value);
119 119
120void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size); 120void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size);
121 121
122xs_str *xs_hex_enc(const xs_val *data, int size);
123xs_val *xs_hex_dec(const xs_str *hex, int *size);
124int xs_is_hex(const char *str);
125
126unsigned int xs_hash_func(const char *data, int size); 122unsigned int xs_hash_func(const char *data, int size);
127 123
128#ifdef XS_ASSERT 124#ifdef XS_ASSERT
@@ -1178,75 +1174,6 @@ void *xs_memmem(const char *haystack, int h_size, const char *needle, int n_size
1178} 1174}
1179 1175
1180 1176
1181/** hex **/
1182
1183static char xs_hex_digits[] = "0123456789abcdef";
1184
1185xs_str *xs_hex_enc(const xs_val *data, int size)
1186/* returns an hexdump of data */
1187{
1188 xs_str *s;
1189 char *p;
1190 int n;
1191
1192 p = s = xs_realloc(NULL, _xs_blk_size(size * 2 + 1));
1193
1194 for (n = 0; n < size; n++) {
1195 *p++ = xs_hex_digits[*data >> 4 & 0xf];
1196 *p++ = xs_hex_digits[*data & 0xf];
1197 data++;
1198 }
1199
1200 *p = '\0';
1201
1202 return s;
1203}
1204
1205
1206xs_val *xs_hex_dec(const xs_str *hex, int *size)
1207/* decodes an hexdump into data */
1208{
1209 int sz = strlen(hex);
1210 xs_val *s = NULL;
1211 char *p;
1212 int n;
1213
1214 if (sz % 2)
1215 return NULL;
1216
1217 p = s = xs_realloc(NULL, _xs_blk_size(sz / 2 + 1));
1218
1219 for (n = 0; n < sz; n += 2) {
1220 int i;
1221 if (sscanf(&hex[n], "%02x", &i) == 0) {
1222 /* decoding error */
1223 return xs_free(s);
1224 }
1225 else
1226 *p = i;
1227
1228 p++;
1229 }
1230
1231 *p = '\0';
1232 *size = sz / 2;
1233
1234 return s;
1235}
1236
1237
1238int xs_is_hex(const char *str)
1239/* returns 1 if str is an hex string */
1240{
1241 while (*str) {
1242 if (strchr("0123456789abcdefABCDEF", *str++) == NULL)
1243 return 0;
1244 }
1245
1246 return 1;
1247}
1248
1249
1250unsigned int xs_hash_func(const char *data, int size) 1177unsigned int xs_hash_func(const char *data, int size)
1251/* a general purpose hashing function */ 1178/* a general purpose hashing function */
1252{ 1179{