Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwpl.git;a=commitdiff;h=53a76242bc26ddf3af34996e89d52b1e3d8ea4cf
commit 53a76242bc26ddf3af34996e89d52b1e3d8ea4cf Author: James Buren <[email protected]> Date: Thu Sep 17 14:49:06 2009 -0500 utility.c * initial draft diff --git a/src/utility.c b/src/utility.c new file mode 100644 index 0000000..bff6d9b --- /dev/null +++ b/src/utility.c @@ -0,0 +1,67 @@ +#include <stdlib.h> +#include <string.h> +#include <stdio.h> +#include <stdarg.h> +#include <iso646.h> +#include <assert.h> +#include "utility.h" + +void *xmalloc(size_t size) { + void *ptr; + + assert(size); + + ptr = malloc(size); + + if(!ptr) { + eprintf("Memory allocation failure of %u bytes.\n",size); + abort(); + } + + return ptr; +} + +char *xstrdup(const char *str1) { + char *str; + size_t size; + + assert(str1); + + size = (strlen(str1) + 1) * sizeof(*str); + + str = xmalloc(size); + + strcpy(str,str1); + + return str; +} + +char *xstrcmb(const char *str1,const char *str2) { + char *str; + size_t size; + + assert(str1 and str2); + + size = (strlen(str1) + strlen(str2) + 1) * sizeof(*str); + + str = xmalloc(size); + + strcpy(stpcpy(str,str1),str2); + + return str; +} + +int eprintf(const char *fmt,...) { + va_list args; + int ret; + + assert(fmt); + + va_start(args,fmt); + + ret = vfprintf(stderr,fmt,args); + + va_end(args); + + return ret; +} _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
