1/* $Id$ $Revision$ */
2/* vim:set shiftwidth=4 ts=8: */
3
4/*************************************************************************
5 * Copyright (c) 2011 AT&T Intellectual Property
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors: See CVS logs. Details at http://www.graphviz.org/
12 *************************************************************************/
13
14#include "config.h"
15
16#include <stdio.h>
17#include <string.h>
18#include "memory.h"
19
20void *zmalloc(size_t nbytes)
21{
22 char *rv;
23 if (nbytes == 0)
24 return 0;
25 rv = gmalloc(nbytes);
26 memset(rv, 0, nbytes);
27 return rv;
28}
29
30void *zrealloc(void *ptr, size_t size, size_t elt, size_t osize)
31{
32 void *p = realloc(ptr, size * elt);
33 if (p == NULL && size) {
34 fprintf(stderr, "out of memory\n");
35 return p;
36 }
37 if (osize < size)
38 memset((char *) p + (osize * elt), '\0', (size - osize) * elt);
39 return p;
40}
41
42void *gmalloc(size_t nbytes)
43{
44 char *rv;
45 if (nbytes == 0)
46 return NULL;
47 rv = malloc(nbytes);
48 if (rv == NULL) {
49 fprintf(stderr, "out of memory\n");
50 }
51 return rv;
52}
53
54void *grealloc(void *ptr, size_t size)
55{
56 void *p = realloc(ptr, size);
57 if (p == NULL && size) {
58 fprintf(stderr, "out of memory\n");
59 }
60 return p;
61}
62