/*
 | common.c (12 May 1998)
 | by Paul Clifford (paul@plasma.demon.co.uk)
 */

#include <stdio.h>
#include <stdlib.h>

#include "common.h"


/*
 | Safe memory allocation
 */

void *
xmalloc(size_t size) {
    void *mem;
    if ((mem = malloc(size)) == 0) {
        fprintf(stderr, "Insufficient memory for malloc\n");
        exit(EXIT_FAILURE);
    }
    return(mem);
}

void *
xrealloc(void *mem, size_t size) {
    if ((mem = realloc(mem, size)) == 0) {
        fprintf(stderr, "Insufficient memory for realloc\n");
        exit(EXIT_FAILURE);
    }
    return(mem);
}
