From 4e0f4aa68e082b469663e3ebc8ec83c9400dab4b Mon Sep 17 00:00:00 2001 From: Jeroen Nijhof Date: Wed, 22 Dec 2010 11:12:08 +0100 Subject: Initial commit --- libtac/lib/xalloc.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 libtac/lib/xalloc.c (limited to 'libtac/lib/xalloc.c') diff --git a/libtac/lib/xalloc.c b/libtac/lib/xalloc.c new file mode 100644 index 0000000..88bbb28 --- /dev/null +++ b/libtac/lib/xalloc.c @@ -0,0 +1,43 @@ +/* xalloc.c - Failsafe memory allocation functions. + * Taken from excellent glibc.info ;) + * + * Copyright (C) 2010, Pawel Krawczyk and + * Jeroen Nijhof + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program - see the file COPYING. + * + * See `CHANGES' file for revision history. + */ + +#include +#include + +void *xcalloc(size_t nmemb, size_t size) { + register void *val = calloc(nmemb, size); + if(val == 0) { + syslog(LOG_ERR, "%s: calloc(%u,%u) failed", __FUNCTION__, + (unsigned) nmemb, (unsigned) size); + exit(1); + } + return val; +} + +void *xrealloc(void *ptr, size_t size) { + register void *val = realloc(ptr, size); + if(val == 0) { + syslog(LOG_ERR, "%s: realloc(%u) failed", __FUNCTION__, (unsigned) size); + exit(1); + } + return val; +} -- cgit v1.2.3