OSDN Git Service

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