/*
 * xmalloc.c - malloc that can't fail
 *
 * Copyright (C) 2003-2005  Joshua Hoblitt, 2003  Robert Lupton
 *
 * $Id: xmalloc.c,v 1.3 2005-07-30 02:45:31 jhoblitt Exp $
 */

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

/*****************************************************************************/
/*
 * Wrappers for malloc/free.  xmalloc cannot fail.
 */
void * xmalloc(size_t n)
{
   void *ptr = malloc(n);
    
   if (ptr == NULL) {
      perror("malloc");
      exit(EXIT_FAILURE);
   }
 
   return(ptr);
}

void * xrealloc(void *ptr, size_t size)
{
    void *newptr = realloc(ptr, size);

    if (!newptr) {
        perror("realloc");
        exit(EXIT_FAILURE);
    } 

    return(newptr);
}
 
void xfree(void *ptr)
{
   free(ptr);
}
