summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c26
-rw-r--r--src/shared/util.h2
2 files changed, 28 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 7281cc8ab8..873c95820a 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -1069,6 +1069,32 @@ char *hexmem(const void *p, size_t l) {
return r;
}
+void *unhexmem(const char *p, size_t l) {
+ uint8_t *r, *z;
+ const char *x;
+
+ assert(p);
+
+ z = r = malloc((l + 1) / 2 + 1);
+ if (!r)
+ return NULL;
+
+ for (x = p; x < p + l; x += 2) {
+ int a, b;
+
+ a = unhexchar(x[0]);
+ if (x+1 < p + l)
+ b = unhexchar(x[1]);
+ else
+ b = 0;
+
+ *(z++) = (uint8_t) a << 4 | (uint8_t) b;
+ }
+
+ *z = 0;
+ return r;
+}
+
char octchar(int x) {
return '0' + (x & 7);
}
diff --git a/src/shared/util.h b/src/shared/util.h
index 485733f650..0d05cd6653 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -609,5 +609,7 @@ static inline void *mempset(void *s, int c, size_t n) {
}
char *hexmem(const void *p, size_t l);
+void *unhexmem(const char *p, size_t l);
+
char *strextend(char **x, ...);
char *strrep(const char *s, unsigned n);