summaryrefslogtreecommitdiff
path: root/hald/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'hald/util.c')
-rw-r--r--hald/util.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/hald/util.c b/hald/util.c
index c7f80abe..7fa3011b 100644
--- a/hald/util.c
+++ b/hald/util.c
@@ -1228,3 +1228,36 @@ is_valid_interface_name (const char *name) {
return TRUE;
}
+static int
+hexdigit (char c)
+{
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ if (c >= 'a' && c <= 'f')
+ return c - 'a';
+ if (c >= 'A' && c <= 'F')
+ return c - 'A';
+ HAL_ERROR (("'%c' is not a valid hex digit", c));
+ return 0;
+}
+
+/* Decode string with \xNN escapes */
+void
+hal_util_decode_escape (const char* src, char* result, int maxlen)
+{
+ int len;
+
+ if (src == NULL || maxlen == 0)
+ return;
+
+ for (len = 0; len < maxlen && *src; ++len) {
+ /* note that C's short-circuiting avoids reading past \0 */
+ if (*src == '\\' && src[1] == 'x' && isalnum (src[2]) && isalnum (src[3])) {
+ result[len] = (hexdigit(src[2]) << 4) | hexdigit(src[3]);
+ src += 4;
+ } else
+ result[len] = *src++;
+ }
+}
+
+