Back to index

lightning-sunbird  0.9+nobinonly
xmalloc.c
Go to the documentation of this file.
00001 /*
00002  * Copyright © 2004 Red Hat, Inc.
00003  *
00004  * Permission to use, copy, modify, distribute, and sell this software
00005  * and its documentation for any purpose is hereby granted without
00006  * fee, provided that the above copyright notice appear in all copies
00007  * and that both that copyright notice and this permission notice
00008  * appear in supporting documentation, and that the name of
00009  * Red Hat, Inc. not be used in advertising or publicity pertaining to
00010  * distribution of the software without specific, written prior
00011  * permission. Red Hat, Inc. makes no representations about the
00012  * suitability of this software for any purpose.  It is provided "as
00013  * is" without express or implied warranty.
00014  *
00015  * RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
00016  * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
00017  * FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
00018  * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
00019  * RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
00020  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
00021  * IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00022  *
00023  * Author: Carl D. Worth <cworth@cworth.org>
00024  */
00025 
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 
00029 #include "xmalloc.h"
00030 
00031 void *
00032 xmalloc (size_t size)
00033 {
00034     void *buf;
00035 
00036     buf = malloc (size);
00037     if (!buf) {
00038        fprintf (stderr, "Error: Out of memory. Exiting.\n");
00039        exit (1);
00040     }
00041 
00042     return buf;
00043 }
00044 
00045 void *
00046 xcalloc (size_t nmemb, size_t size)
00047 {
00048     void *buf;
00049 
00050     buf = calloc (nmemb, size);
00051     if (!buf) {
00052        fprintf (stderr, "Error: Out of memory. Exiting\n");
00053        exit (1);
00054     }
00055 
00056     return buf;
00057 }
00058