summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2008-02-09 17:31:21 +0100
committerFelix Fietkau <nbd@openwrt.org>2008-02-09 17:31:21 +0100
commit9f540f2106dcf724e4b8c41489d4bda6ccfe65d8 (patch)
tree7ed35799aa4d586dff069f12ca03f3a9d10ce731 /util.c
parent20925c2795005338ae4de0149201f406ba7e6786 (diff)
downloaduci-9f540f2106dcf724e4b8c41489d4bda6ccfe65d8.tar.gz
reorganize some code, add an extra command for adding unnamed sections
Diffstat (limited to 'util.c')
-rw-r--r--util.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/util.c b/util.c
index eb50b89..f098c4b 100644
--- a/util.c
+++ b/util.c
@@ -13,8 +13,8 @@
*/
/*
- * This file contains wrappers to standard functions, which
- * throw exceptions upon failure.
+ * This file contains misc utility functions and wrappers to standard
+ * functions, which throw exceptions upon failure.
*/
#include <sys/types.h>
#include <sys/stat.h>
@@ -59,6 +59,22 @@ static char *uci_strdup(struct uci_context *ctx, const char *str)
return ptr;
}
+/* Based on an efficient hash function published by D. J. Bernstein */
+static unsigned int djbhash(unsigned int hash, char *str)
+{
+ int len = strlen(str);
+ int i;
+
+ /* initial value */
+ if (hash == ~0)
+ hash = 5381;
+
+ for(i = 0; i < len; i++) {
+ hash = ((hash << 5) + hash) + str[i];
+ }
+ return (hash & 0x7FFFFFFF);
+}
+
/*
* validate strings for names and types, reject special characters
* for names, only alphanum and _ is allowed (shell compatibility)
@@ -125,7 +141,7 @@ lastval:
*value = last;
}
- if (*section && !uci_validate_name(*section))
+ if (*section && *section[0] && !uci_validate_name(*section))
goto error;
if (*option && !uci_validate_name(*option))
goto error;