/* misc.c -- misc utility routines for ASpringies
 * Copyright (C) 1991  Douglas M. DeCarlo
 *
 * Modifications for the Amiga port Copyright (C) 1994  Torsten Klein
 *
 * This file is part of ASpringies, a mass and spring simulation system for the Amiga
 *
 * ASpringies is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 1, or (at your option)
 * any later version.
 *
 * ASpringies is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with ASpringies; see the file COPYING.  If not, write to
 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * $Id: misc.c,v 1.5 1994/06/26 20:42:58 Torsten_Klein Exp $
 */

#include "defs.h"
#include "main.h"

/* malloc space, and call main_fail if allocation fails 
 */
char *xmalloc (int size)
{
  register char *tmp = (char *)malloc(size);

  if (!tmp) {
    delete_all();
    main_fail("memory for dynamic arrays (xmalloc)", __FILE__, __LINE__);
  }
  return tmp;
}

/* realloc space, and call main_fail if re-allocation fails
 *   (also, call malloc if ptr is NULL) 
 */
char *xrealloc (char *ptr, int size)
{
  register char *tmp;

  if (ptr == NULL)
    return (char *)xmalloc(size);

  tmp = (char *)realloc(ptr, size);
  
  if (!tmp) {
    delete_all();
    main_fail("memory for dynamic arrays (xrealloc)", __FILE__, __LINE__);
  }
  return tmp;
}


