Debian Codegraph @

texk/dvipdfm-x/mem.c

raw
1 /* This is dvipdfmx, an eXtended version of dvipdfm by Mark A. Wicks.
2
3 Copyright (C) 2002-2020 by Jin-Hwan Cho and Shunsaku Hirata,
4 the dvipdfmx project team.
5
6 Copyright (C) 1998, 1999 by Mark A. Wicks <[email protected]>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
21 */
22
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
26
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #include "system.h"
31 #include "mem.h"
32 #include "error.h"
33
34 void *new (uint32_t size)
35 {
36 void *result = malloc ((size_t)size);
37 if (!result) {
38 ERROR("Out of memory - asked for %u bytes\n", size);
39 }
40
41 return result;
42 }
43
44 void *renew (void *mem, uint32_t size)
45 {
46 if (size) {
47 void *result = realloc (mem, (size_t)size);
48 if (!result) {
49 ERROR("Out of memory - asked for %u bytes\n", size);
50 }
51 return result;
52 } else {
53 /* realloc may not return NULL if size == 0 */
54 free(mem);
55 return NULL;
56 }
57 }