/misc/src/release/graphviz-2.18-1/src/graphviz-2.18/lib/common/memory.c

Go to the documentation of this file.
00001 /* $Id: memory.c,v 1.3 2005/10/18 21:06:26 ellson Exp $ $Revision: 1.3 $ */
00002 /* vim:set shiftwidth=4 ts=8: */
00003 
00004 /**********************************************************
00005 *      This software is part of the graphviz package      *
00006 *                http://www.graphviz.org/                 *
00007 *                                                         *
00008 *            Copyright (c) 1994-2004 AT&T Corp.           *
00009 *                and is licensed under the                *
00010 *            Common Public License, Version 1.0           *
00011 *                      by AT&T Corp.                      *
00012 *                                                         *
00013 *        Information and Software Systems Research        *
00014 *              AT&T Research, Florham Park NJ             *
00015 **********************************************************/
00016 
00017 #ifdef HAVE_CONFIG_H
00018 #include "config.h"
00019 #endif
00020 
00021 #include <stdio.h>
00022 #include <string.h>
00023 #include "memory.h"
00024 
00025 void *zmalloc(size_t nbytes)
00026 {
00027     char *rv;
00028     if (nbytes == 0)
00029         return 0;
00030     rv = gmalloc(nbytes);
00031     memset(rv, 0, nbytes);
00032     return rv;
00033 }
00034 
00035 void *zrealloc(void *ptr, size_t size, size_t elt, size_t osize)
00036 {
00037     void *p = realloc(ptr, size * elt);
00038     if (p == NULL && size) {
00039         fprintf(stderr, "out of memory\n");
00040         abort();
00041     }
00042     if (osize < size)
00043         memset((char *) p + (osize * elt), '\0', (size - osize) * elt);
00044     return p;
00045 }
00046 
00047 void *gmalloc(size_t nbytes)
00048 {
00049     char *rv;
00050     if (nbytes == 0)
00051         return NULL;
00052     rv = malloc(nbytes);
00053     if (rv == NULL) {
00054         fprintf(stderr, "out of memory\n");
00055         abort();
00056     }
00057     return rv;
00058 }
00059 
00060 void *grealloc(void *ptr, size_t size)
00061 {
00062     void *p = realloc(ptr, size);
00063     if (p == NULL && size) {
00064         fprintf(stderr, "out of memory\n");
00065         abort();
00066     }
00067     return p;
00068 }

Generated on Mon Mar 31 19:03:24 2008 for Graphviz by  doxygen 1.5.1