aboutsummaryrefslogtreecommitdiffstats
path: root/mem.c
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-02-07 11:28:48 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-02-07 11:28:48 +0100
commit5f4b06d150beed1e7d614705386eb7eab0a98be5 (patch)
tree792771807cb2328d4506ad6d49e52b1377c25935 /mem.c
downloadtoolame-dab-5f4b06d150beed1e7d614705386eb7eab0a98be5.tar.gz
toolame-dab-5f4b06d150beed1e7d614705386eb7eab0a98be5.tar.bz2
toolame-dab-5f4b06d150beed1e7d614705386eb7eab0a98be5.zip
add toolame-02l
Diffstat (limited to 'mem.c')
-rw-r--r--mem.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/mem.c b/mem.c
new file mode 100644
index 0000000..216ec2b
--- /dev/null
+++ b/mem.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "common.h"
+#include "mem.h"
+
+/*******************************************************************************
+*
+* Allocate number of bytes of memory equal to "block".
+*
+*******************************************************************************/
+
+void *mem_alloc (unsigned long block, char *item)
+{
+
+ void *ptr;
+
+ ptr = (void *) malloc (block);
+
+ if (ptr != NULL) {
+ memset (ptr, 0, block);
+ } else {
+ fprintf (stderr, "Unable to allocate %s\n", item);
+ exit (0);
+ }
+ return (ptr);
+}
+
+
+/****************************************************************************
+*
+* Free memory pointed to by "*ptr_addr".
+*
+*****************************************************************************/
+
+void mem_free (void **ptr_addr)
+{
+
+ if (*ptr_addr != NULL) {
+ free (*ptr_addr);
+ *ptr_addr = NULL;
+ }
+
+}