Git-Url: 
http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=b8461917d4153b8d7f969a3c7a4e6700005b48e6

commit b8461917d4153b8d7f969a3c7a4e6700005b48e6
Author: James Buren <[email protected]>
Date:   Thu Aug 9 08:21:06 2012 -0500

import utility functions

diff --git a/backend.c b/backend.c
deleted file mode 100644
index 6efe048..0000000
--- a/backend.c
+++ /dev/null
@@ -1,78 +0,0 @@
-#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
deleted file mode 100644
index ae45738..0000000
--- a/backend.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#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);
diff --git a/utility.c b/utility.c
new file mode 100644
index 0000000..c7ac12f
--- /dev/null
+++ b/utility.c
@@ -0,0 +1,40 @@
+#include "utility.h"
+
+extern void *alloc(size_t n)
+{
+       assert(n > 0);
+
+       void *p = malloc(n);
+
+       if(p == 0)
+               abort();
+
+       return p;
+}
+
+extern void *alloc0(size_t n)
+{
+       assert(n > 0);
+
+       void *p = malloc(n);
+
+       if(p == 0)
+               abort();
+
+       memset(p,0,n);
+
+       return p;
+}
+
+extern void *redim(void *p,size_t n)
+{
+       assert(p != 0);
+       assert(n > 0);
+
+       p = realloc(p,n);
+
+       if(p == 0)
+               abort();
+
+       return p;
+}
diff --git a/utility.h b/utility.h
new file mode 100644
index 0000000..ff8efcd
--- /dev/null
+++ b/utility.h
@@ -0,0 +1,11 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#define talloc(T,N)  ((T*)alloc(sizeof(T)*(N)))
+#define talloc0(T,N) ((T*)alloc0(sizeof(T)*(N)))
+
+extern void *alloc(size_t);
+extern void *alloc0(size_t);
+extern void *redim(void *,size_t);
_______________________________________________
Frugalware-git mailing list
[email protected]
http://frugalware.org/mailman/listinfo/frugalware-git

Reply via email to