1 /* misc.c -- misc utility routines for xspringies
2 * Copyright (C) 1991,1992 Douglas M. DeCarlo
3 *
4 * This file is part of XSpringies, a mass and spring simulation system for X
5 *
6 * XSpringies is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 1, or (at your option)
9 * any later version.
10 *
11 * XSpringies is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with XSpringies; see the file COPYING. If not, write to
18 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 */
21
22 #include "defs.h"
23
24 #if defined(__STRICT_BSD__) || defined(__STDC__) || defined(_ANSI_C_SOURCE)
25 extern void *malloc(), *realloc();
26 #else
27 extern char *malloc(), *realloc();
28 #endif
29
30 /* malloc space, and call fatal if allocation fails */
xmalloc(size)31 char *xmalloc (size)
32 int size;
33 {
34 register char *tmp = (char *)malloc(size);
35
36 if (!tmp)
37 fatal ("Out of memory");
38
39 return tmp;
40 }
41
42 /* realloc space, and call fatal if re-allocation fails
43 (also, call malloc if ptr is NULL) */
xrealloc(ptr,size)44 char *xrealloc (ptr, size)
45 char *ptr;
46 int size;
47 {
48 register char *tmp;
49
50 if (ptr == NULL)
51 return (char *)xmalloc(size);
52
53 tmp = (char *)realloc(ptr, size);
54
55 if (!tmp)
56 fatal ("Out of memory");
57
58 return tmp;
59 }
60