summaryrefslogtreecommitdiff
path: root/rpmio/rpmmalloc.c
blob: 94167b650fd5a96f8cca195be4575d94e69b0abb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "system.h"

void *vmefail(void)
{
    fprintf(stderr, _("memory alloc returned NULL.\n"));
    exit(EXIT_FAILURE);
    /*@notreached@*/
    return NULL;
}

#if !(HAVE_MCHECK_H && defined(__GNUC__))

void * xmalloc (size_t size)
{
    register void *value;
    if (size == 0) size++;
    value = malloc (size);
    if (value == 0)
	value = vmefail();
    return value;
}

void * xcalloc (size_t nmemb, size_t size)
{
    register void *value;
    if (size == 0) size++;
    if (nmemb == 0) nmemb++;
    value = calloc (nmemb, size);
    if (value == 0)
	value = vmefail();
    return value;
}

void * xrealloc (void *ptr, size_t size)
{
    register void *value;
    if (size == 0) size++;
    value = realloc (ptr, size);
    if (value == 0)
	value = vmefail();
    return value;
}

char * xstrdup (const char *str)
{
    char *newstr = (char *) malloc (strlen(str) + 1);
    if (newstr == 0)
	newstr = (char *) vmefail();
    strcpy (newstr, str);
    return newstr;
}

#endif	/* !(HAVE_MCHECK_H && defined(__GNUC__)) */