OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
xmalloc.c
Go to the documentation of this file.
1 /*
2  Copyright (C) 2004, Remik Ziemlinski <first d0t surname att n0aa d0t g0v>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2, or (at your option)
7  any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; see the file COPYING.
16  If not, write to the Free Software Foundation,
17  59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19 
20 #include "common.h"
21 
22 void*
23 xmalloc(size_t num) {
24  void* new = (void*) malloc(num);
25  if (!new) {
26  fprintf(stderr, "Memory exhausted\n");
27  exit(EXIT_FATAL);
28  }
29 
30  return new;
31 }
32 
33 void*
34 xrealloc(void* p, size_t num) {
35  void* new;
36 
37  if (!p)
38  return xmalloc(num);
39 
40  new = (void*) realloc(p, num);
41  if (!new) {
42  fprintf(stderr, "Memory exhausted\n");
43  exit(EXIT_FATAL);
44  }
45 
46  return new;
47 }
48 
49 void*
50 xcalloc(size_t num, size_t size) {
51  void* new = (void*) xmalloc(num * size);
52  bzero(new, num * size);
53  return new;
54 }
55 
void * xmalloc(size_t num)
Definition: xmalloc.c:23
void * xcalloc(size_t num, size_t size)
Definition: xmalloc.c:50
void * xrealloc(void *p, size_t num)
Definition: xmalloc.c:34
void bzero()
#define EXIT_FATAL
Definition: common.h:85
float p[MODELMAX]
Definition: atrem_corl1.h:131