aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tileserver/Makefile31
-rw-r--r--tileserver/util.c53
-rw-r--r--tileserver/util.h36
3 files changed, 120 insertions, 0 deletions
diff --git a/tileserver/Makefile b/tileserver/Makefile
new file mode 100644
index 000000000..b9ffc302f
--- /dev/null
+++ b/tileserver/Makefile
@@ -0,0 +1,31 @@
+#
+# Makefile:
+# Build tile server.
+#
+# Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
+# Email: chris@mysociety.org; WWW: http://www.mysociety.org/
+#
+# $Id: Makefile,v 1.1 2006-09-20 15:45:51 chris Exp $
+#
+
+CFLAGS = -Wall -g -O99 -I/software/include
+LDFLAGS = -L/software/lib
+LDLIBS = -lfcgi
+
+# for debugging
+#CFLAGS += -DNO_FASTCGI
+
+SRCS = base64.c cdb.c netstring.c tileserver.c tileset.c util.c
+OBJS = $(SRCS:.c=.o)
+HDRS = base64.h cdb.h netstring.h tileset.h util.h
+TXTS =
+
+tileserver: Makefile $(OBJS)
+ $(CC) -o tileserver $(OBJS) $(LDFLAGS) $(LDLIBS)
+
+clean:
+ rm -f tileserver $(OBJS) *~ core
+
+%.o: %.c Makefile
+ $(CC) $(CFLAGS) -c -o $@ $<
+
diff --git a/tileserver/util.c b/tileserver/util.c
new file mode 100644
index 000000000..fbc500438
--- /dev/null
+++ b/tileserver/util.c
@@ -0,0 +1,53 @@
+/*
+ * util.c:
+ * Miscellaneous utility functions.
+ *
+ * Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
+ * Email: chris@mysociety.org; WWW: http://www.mysociety.org/
+ *
+ */
+
+static const char rcsid[] = "$Id: util.c,v 1.1 2006-09-20 15:45:51 chris Exp $";
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "util.h"
+
+/*
+ * Wrappers for memory-allocation functions.
+ */
+void *xmalloc(const size_t s) {
+ void *v;
+ if (!(v = malloc(s)))
+ die("malloc(%u bytes): %s", (unsigned)s, strerror(errno));
+ return v;
+}
+
+void *xcalloc(const size_t a, const size_t b) {
+ void *v;
+ if (!(v = calloc(a, b)))
+ die("calloc(%u * %u bytes): %s",
+ (unsigned)a, (unsigned)b, strerror(errno));
+ return v;
+}
+
+void *xrealloc(void *b, const size_t s) {
+ void *v;
+ if (!(v = realloc(b, s)))
+ die("realloc(%u bytes): %s", (unsigned)s, strerror(errno));
+ return v;
+}
+
+char *xstrdup(const char *s) {
+ char *t;
+ if (!(t = strdup(s)))
+ die("strdup(%u bytes): %s", (unsigned)(strlen(s) + 1), strerror(errno));
+ return t;
+}
+
+void xfree(void *v) {
+ if (v) free(v);
+}
diff --git a/tileserver/util.h b/tileserver/util.h
new file mode 100644
index 000000000..a2f1f7bc8
--- /dev/null
+++ b/tileserver/util.h
@@ -0,0 +1,36 @@
+/*
+ * util.h:
+ * Utilities.
+ *
+ * Copyright (c) 2006 UK Citizens Online Democracy. All rights reserved.
+ * Email: chris@mysociety.org; WWW: http://www.mysociety.org/
+ *
+ * $Id: util.h,v 1.1 2006-09-20 15:45:51 chris Exp $
+ *
+ */
+
+#ifndef __UTIL_H_ /* include guard */
+#define __UTIL_H_
+
+/* err FORMAT [ARG ...]
+ * Write an error message to standard error. */
+ /* XXX format this with a timestamp for the error-log? */
+#define err(...) \
+ do { \
+ fprintf(stderr, "tileserver: "); \
+ fprintf(stderr, __VA_ARGS__); \
+ fprintf(stderr, "\n"); \
+ } while (0)
+
+/* die FORMAT [ARG ...]
+ * Write an error message to standard error and exit unsuccessfully. */
+#define die(...) do { err(__VA_ARGS__); exit(1); } while (0)
+
+/* util.c */
+void *xmalloc(const size_t s);
+void *xcalloc(const size_t a, const size_t b);
+void *xrealloc(void *b, const size_t s);
+char *xstrdup(const char *s);
+void xfree(void *v);
+
+#endif /* __UTIL_H_ */