- Main Page
- Modules
- Data Structures
- Files
- Related Pages

- File List
- Globals

# rpmio/rpmmalloc.c

Go to the documentation of this file.

    00001
    00005 #include "system.h"
    00006 #include "debug.h"
    00007
    00008 #if !defined(EXIT_FAILURE)
    00009 #define EXIT_FAILURE    1
    00010 #endif
    00011
    00012 /*@-modfilesys@*/
    00013 /*@only@*/ void *vmefail(size_t size)
    00014 {
    00015     fprintf(stderr, _("memory alloc (%u bytes) returned NULL.\n"), (unsigned)size);
    00016     exit(EXIT_FAILURE);
    00017     /*@notreached@*/
    00018     return NULL;
    00019 }
    00020 /*@=modfilesys@*/
    00021
    00022 #if !(HAVE_MCHECK_H && defined(__GNUC__)) && !defined(__LCLINT__)
    00023
    00024 /*@out@*/ /*@only@*/ void * xmalloc (size_t size)
    00025 {
    00026     register void *value;
    00027     if (size == 0) size++;
    00028     value = malloc (size);
    00029     if (value == 0)
    00030         value = vmefail(size);
    00031     return value;
    00032 }
    00033
    00034 /*@only@*/ void * xcalloc (size_t nmemb, size_t size)
    00035 {
    00036     register void *value;
    00037     if (size == 0) size++;
    00038     if (nmemb == 0) nmemb++;
    00039     value = calloc (nmemb, size);
    00040     if (value == 0)
    00041         value = vmefail(size);
    00042     return value;
    00043 }
    00044
    00045 /*@only@*/ void * xrealloc (/*@only@*/ void *ptr, size_t size)
    00046 {
    00047     register void *value;
    00048     if (size == 0) size++;
    00049     value = realloc (ptr, size);
    00050     if (value == 0)
    00051         value = vmefail(size);
    00052     return value;
    00053 }
    00054
    00055 /*@only@*/ char * xstrdup (const char *str)
    00056 {
    00057     size_t size = strlen(str) + 1;
    00058     char *newstr = (char *) malloc (size);
    00059     if (newstr == 0)
    00060         newstr = (char *) vmefail(size);
    00061     strcpy (newstr, str);
    00062     return newstr;
    00063 }
    00064
    00065 #endif  /* !(HAVE_MCHECK_H && defined(__GNUC__)) */