summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2010-08-20 14:56:30 +0200
committerFelix Fietkau <nbd@openwrt.org>2010-08-20 14:56:30 +0200
commit853f586e4894aba060372b4655334921cda10464 (patch)
tree44993506b7d917e69e51b91b20f58230032ff56a
parent82db7b24855fbf5815d059c7cf6ab5f3f4ee44f0 (diff)
downloaduci-853f586e4894aba060372b4655334921cda10464.tar.gz
split off and compile util.c separately
-rw-r--r--Makefile7
-rw-r--r--libuci.c1
-rw-r--r--list.c16
-rw-r--r--util.c22
4 files changed, 26 insertions, 20 deletions
diff --git a/Makefile b/Makefile
index c3d79e4..b00aac8 100644
--- a/Makefile
+++ b/Makefile
@@ -19,10 +19,11 @@ $(1).shared.o: $(2)
$(1).static.o: $(2)
endef
+SOURCES = libuci.c file.c ucimap.c util.c
all: uci libuci.$(SHLIB_EXT) uci-static ucimap-example
-$(eval $(call add_dep,libuci,history.c list.c util.c uci.h uci_config.h uci_internal.h))
+$(eval $(call add_dep,libuci,history.c list.c uci.h uci_config.h uci_internal.h))
$(eval $(call add_dep,ucimap,uci.h uci_config.h ucimap.h))
cli.o: cli.c uci.h uci_config.h
@@ -56,12 +57,12 @@ uci-static: cli.o libuci.a
ucimap.c: ucimap.h uci.h
-libuci.a: libuci.static.o ucimap.static.o file.static.o
+libuci.a: $(patsubst %.c,%.static.o, $(SOURCES))
rm -f $@
$(AR) rc $@ $^
$(RANLIB) $@
-libuci.$(SHLIB_EXT): libuci.shared.o file.shared.o ucimap.shared.o
+libuci.$(SHLIB_EXT): $(patsubst %.c,%.shared.o, $(SOURCES))
$(LINK) $(SHLIB_FLAGS) -o $(SHLIB_FILE) $^ $(LIBS)
ln -sf $(SHLIB_FILE) $@
diff --git a/libuci.c b/libuci.c
index 6e9587b..5b22ef1 100644
--- a/libuci.c
+++ b/libuci.c
@@ -43,7 +43,6 @@ static const char *uci_errstr[] = {
static void uci_unload_plugin(struct uci_context *ctx, struct uci_plugin *p);
#include "uci_internal.h"
-#include "util.c"
#include "list.c"
#include "history.c"
diff --git a/list.c b/list.c
index fb9d38a..1a080fa 100644
--- a/list.c
+++ b/list.c
@@ -127,6 +127,22 @@ uci_alloc_list(struct uci_section *s, const char *name)
return o;
}
+/* 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);
+}
+
/* fix up an unnamed section, e.g. after adding options to it */
__private void uci_fixup_section(struct uci_context *ctx, struct uci_section *s)
{
diff --git a/util.c b/util.c
index d44114d..1db3366 100644
--- a/util.c
+++ b/util.c
@@ -16,6 +16,7 @@
* This file contains misc utility functions and wrappers to standard
* functions, which throw exceptions upon failure.
*/
+#define _GNU_SOURCE
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
@@ -24,6 +25,11 @@
#include <ctype.h>
#include <fcntl.h>
#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "uci.h"
+#include "uci_internal.h"
__plugin void *uci_malloc(struct uci_context *ctx, size_t size)
{
@@ -57,22 +63,6 @@ __plugin 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)