summaryrefslogtreecommitdiffstats
path: root/polyp/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2004-11-08 23:48:19 +0000
committerLennart Poettering <lennart@poettering.net>2004-11-08 23:48:19 +0000
commit4bb14837dd09777e45793bda42512d900c6b500e (patch)
tree65a8a5a11b4a99707c009a197335554e6e219f91 /polyp/util.c
parentb55923a8d33a1c4ed2f892a0da36c9c679e7d828 (diff)
implemented pax11publish.c
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@275 fefdeb5f-60dc-0310-8127-8f9354f1896f
Diffstat (limited to 'polyp/util.c')
-rw-r--r--polyp/util.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/polyp/util.c b/polyp/util.c
index 97b3a26b..b4c16dbb 100644
--- a/polyp/util.c
+++ b/polyp/util.c
@@ -732,3 +732,44 @@ char *pa_hexstr(const uint8_t* d, size_t dlength, char *s, size_t slength) {
s[j < slength ? j : slength] = 0;
return s;
}
+
+/* Convert a hexadecimal digit to a number or -1 if invalid */
+static int hexc(char c) {
+ if (c >= '0' && c <= '9')
+ return c - '0';
+
+ if (c >= 'A' && c <= 'F')
+ return c - 'A' + 10;
+
+ if (c >= 'a' && c <= 'f')
+ return c - 'a' + 10;
+
+ return -1;
+}
+
+/* Parse a hexadecimal string as created by pa_hexstr() to a BLOB */
+size_t pa_parsehex(const char *p, uint8_t *d, size_t dlength) {
+ size_t j = 0;
+ assert(p && d);
+
+ while (j < dlength && *p) {
+ int b;
+
+ if ((b = hexc(*(p++))) < 0)
+ return (size_t) -1;
+
+ d[j] = (uint8_t) (b << 4);
+
+ if (!*p)
+ return (size_t) -1;
+
+ if ((b = hexc(*(p++))) < 0)
+ return (size_t) -1;
+
+ d[j] |= (uint8_t) b;
+
+ j++;
+ }
+
+ return j;
+}