]>
Commit | Line | Data |
---|---|---|
8b6dba81 | 1 | /* Memory management routines. |
e3c063ce | 2 | Copyright (C) 2002-2013 Free Software Foundation, Inc. |
6de9cd9a DN |
3 | Contributed by Paul Brook <paul@nowt.org> |
4 | ||
bb408e87 | 5 | This file is part of the GNU Fortran runtime library (libgfortran). |
6de9cd9a | 6 | |
57dea9f6 TM |
7 | Libgfortran is free software; you can redistribute it and/or |
8 | modify it under the terms of the GNU General Public | |
6de9cd9a | 9 | License as published by the Free Software Foundation; either |
748086b7 | 10 | version 3 of the License, or (at your option) any later version. |
57dea9f6 TM |
11 | |
12 | Libgfortran is distributed in the hope that it will be useful, | |
6de9cd9a DN |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
57dea9f6 | 15 | GNU General Public License for more details. |
6de9cd9a | 16 | |
748086b7 JJ |
17 | Under Section 7 of GPL version 3, you are granted additional |
18 | permissions described in the GCC Runtime Library Exception, version | |
19 | 3.1, as published by the Free Software Foundation. | |
20 | ||
21 | You should have received a copy of the GNU General Public License and | |
22 | a copy of the GCC Runtime Library Exception along with this program; | |
23 | see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
24 | <http://www.gnu.org/licenses/>. */ | |
6de9cd9a | 25 | |
6de9cd9a | 26 | #include "libgfortran.h" |
36ae8a61 | 27 | #include <stdlib.h> |
6de9cd9a | 28 | |
6de9cd9a | 29 | |
6de9cd9a | 30 | void * |
1a0fd3d3 | 31 | xmalloc (size_t n) |
6de9cd9a DN |
32 | { |
33 | void *p; | |
34 | ||
1a0fd3d3 JB |
35 | if (n == 0) |
36 | n = 1; | |
37 | ||
38 | p = malloc (n); | |
39 | ||
6de9cd9a DN |
40 | if (p == NULL) |
41 | os_error ("Memory allocation failed"); | |
42 | ||
43 | return p; | |
44 | } | |
45 | ||
46 | ||
f4471acb JB |
47 | /* calloc wrapper that aborts on error. */ |
48 | ||
49 | void * | |
50 | xcalloc (size_t nmemb, size_t size) | |
51 | { | |
52 | if (nmemb * size == 0) | |
53 | nmemb = size = 1; | |
54 | ||
55 | void *p = calloc (nmemb, size); | |
56 | if (!p) | |
57 | os_error ("Allocating cleared memory failed"); | |
58 | ||
59 | return p; | |
60 | } |