/[public]/getopt/trunk/xalloc.h
ViewVC logotype

Annotation of /getopt/trunk/xalloc.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 322 - (hide annotations)
Tue Jul 17 15:27:08 2012 UTC (12 years, 4 months ago) by frodo
File MIME type: text/plain
File size: 856 byte(s)
(Frodo) Revamped the memory management to get in line with util-linux-2.26.
Added an xalloc.h with the memory functions.

1 frodo 322 /*
2     * Copyright (C) 2010 Davidlohr Bueso <dave@gnu.org>
3     *
4     * This file may be redistributed under the terms of the
5     * GNU Lesser General Public License.
6     *
7     * General memory allocation wrappers for malloc, realloc, calloc and strdup
8     */
9    
10     #ifndef UTIL_LINUX_XALLOC_H
11     #define UTIL_LINUX_XALLOC_H
12    
13     #include <stdlib.h>
14     #include <string.h>
15    
16     #ifndef XALLOC_EXIT_CODE
17     # define XALLOC_EXIT_CODE 3
18     #endif
19    
20     static void *xmalloc(const size_t size)
21     {
22     void *ret = malloc(size);
23    
24     if (!ret && size) {
25     fprintf(stderr, "Error: cannot allocate %zu bytes", size);
26     exit(XALLOC_EXIT_CODE);
27     }
28     return ret;
29     }
30    
31     static void *xrealloc(void *ptr, const size_t size)
32     {
33     void *ret = realloc(ptr, size);
34    
35     if (!ret && size)
36     fprintf(stderr, "Error: cannot allocate %zu bytes", size);
37     return ret;
38     }
39    
40     #endif

frodo@frodo.looijaard.name
ViewVC Help
Powered by ViewVC 1.1.26