From e46b7516f01e8f40a0df4f3d43d67e796fa78937 Mon Sep 17 00:00:00 2001 From: chris Date: Wed, 20 Sep 2006 15:45:51 +0000 Subject: Add some missing files. --- tileserver/util.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tileserver/util.c (limited to 'tileserver/util.c') 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 +#include +#include +#include + +#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); +} -- cgit v1.2.3