Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=bcb9b3212adc6d71c1b276151c3e29a48d2501a3
commit bcb9b3212adc6d71c1b276151c3e29a48d2501a3 Author: James Buren <[email protected]> Date: Wed Aug 8 21:52:39 2012 -0500 import backend diff --git a/backend.c b/backend.c new file mode 100644 index 0000000..6efe048 --- /dev/null +++ b/backend.c @@ -0,0 +1,78 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <assert.h> +#include <parted.h> +#include "backend.h" + +static void setup_stderr(void) +{ + static int setup = 0; + + if(setup == 0) + { + stderr = freopen("setup.log","wb",stderr); + + if(!stderr) + abort(); + + setup = 1; + } +} + +extern void eprintf(const char *s,...) +{ + assert(s != 0); + + va_list args; + + setup_stderr(); + + va_start(args,s); + + vfprintf(stderr,s,args); + + va_end(args); +} + +extern void aprintf(const char *s,...) +{ + assert(s != 0); + + va_list args; + + setup_stderr(); + + va_start(args,s); + + vfprintf(stderr,s,args); + + va_end(args); + + abort(); +} + +extern void *allocate(size_t n) +{ + assert(n > 0); + + void *p = malloc(n); + + if(p == 0) + aprintf("Failed to allocate %zu bytes of memory.\n",n); + + return p; +} + +extern void *reallocate(void *p,size_t n) +{ + assert(p != 0); + assert(n > 0); + + p = realloc(p,n); + + if(p == 0) + aprintf("Failed to reallocate to %zu bytes of memory.\n",n); + + return p; +} diff --git a/backend.h b/backend.h new file mode 100644 index 0000000..ae45738 --- /dev/null +++ b/backend.h @@ -0,0 +1,8 @@ +#pragma once + +#include <stddef.h> + +extern void eprintf(const char *s,...); +extern void aprintf(const char *s,...); +extern void *allocate(size_t n); +extern void *reallocate(void *p,size_t n); _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
