Debian Codegraph @

texk/xdvipsk/otflib/mem.c

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