Main Page   Alphabetical List   Data Structures   File List   Data Fields   Globals  

xmalloc.c

00001 /*
00002  *  xmalloc.c - Wrappers for malloc() and realloc(). 
00003  *              This file is part of the FreeLCD package.
00004  *
00005  *  $Id: xmalloc_8c-source.html,v 1.1 2003/02/16 22:50:41 unicorn Exp $
00006  *
00007  *  This program is free software; you can redistribute it and/or modify it
00008  *  under the terms of the GNU General Public License as published by the
00009  *  Free Software Foundation; either version 2 of the License, or (at your
00010  *  option) any later version.
00011  * 
00012  *  This program is distributed in the hope that it will be useful,
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *  GNU General Public License for more details.
00016  *
00017  *  You should have received a copy of the GNU General Public License
00018  *  along with this program; if not, write to the Free Software
00019  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00020  *  MA  02111-1307  USA
00021  *
00022  *  Copyright (c) 2002, 2003, Jeroen van den Berg <unicorn@hippie.nu>
00023  */
00024 
00025 #include <stdlib.h>
00026 #include <syslog.h>
00027 #include <string.h>
00028 
00029 #include "xmalloc.h"
00030 
00031 /*------------------------------------------------------------- xmalloc --*/
00032 void *
00033 xmalloc (size_t size)
00034 {
00035   void *alloc = malloc (size);
00036 
00037   if (alloc == 0)
00038     {
00039       syslog (LOG_ERR, "out of memory (malloc)");
00040       exit (EXIT_FAILURE);
00041     }
00042 
00043   return alloc;
00044 }
00045 
00046 /*------------------------------------------------------------ xrealloc --*/
00047 void *
00048 xrealloc (void *ptr, size_t size)
00049 {
00050   void *alloc;
00051 
00052   if (ptr == 0)
00053     return xmalloc (size);
00054 
00055   alloc = realloc (ptr, size);
00056   if (alloc == 0)
00057     {
00058       syslog (LOG_ERR, "out of memory (realloc)");
00059       exit (EXIT_FAILURE);
00060     }
00061 
00062   return alloc;
00063 }
00064 
00065 /*------------------------------------------------------------- xstrdup --*/
00066 char *
00067 xstrdup (const char *str)
00068 {
00069   char *copy = strdup (str);
00070 
00071   if (copy == 0)
00072     {
00073       syslog (LOG_ERR, "out of memory (strdup)");
00074       exit (EXIT_FAILURE);
00075     }
00076 
00077   return copy;
00078 }

Generated on Sun Feb 16 23:39:49 2003 for FreeLCD by doxygen1.2.18