From 9f540f2106dcf724e4b8c41489d4bda6ccfe65d8 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sat, 9 Feb 2008 17:31:21 +0100 Subject: reorganize some code, add an extra command for adding unnamed sections --- util.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'util.c') 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 #include @@ -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; -- cgit v1.2.1