diff options
author | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-02-07 11:28:48 +0100 |
---|---|---|
committer | Matthias P. Braendli <matthias.braendli@mpb.li> | 2014-02-07 11:28:48 +0100 |
commit | 5f4b06d150beed1e7d614705386eb7eab0a98be5 (patch) | |
tree | 792771807cb2328d4506ad6d49e52b1377c25935 /mem.c | |
download | toolame-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.c | 44 |
1 files changed, 44 insertions, 0 deletions
@@ -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; + } + +} |