diff options
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; +  } + +}  | 
