2 * \file rpmio/rpmmalloc.c
8 static rpmMemFailFunc failfunc = NULL;
9 static void *failfunc_data = NULL;
12 * Give memfail callback a chance to try to give us memory or perform
13 * it's own cleanup. If we dont get memory we die anyway as rpm doesn't
14 * check for NULL returns from allocations.
16 static void *vmefail(size_t size)
18 void *val = failfunc ? (*failfunc)(size, failfunc_data) : NULL;
20 fprintf(stderr, _("memory alloc (%u bytes) returned NULL.\n"),
27 void * rpmSetMemFail(rpmMemFailFunc func, void *data)
29 void *ofunc = failfunc;
35 void * rmalloc (size_t size)
38 if (size == 0) size++;
39 value = malloc (size);
41 value = vmefail(size);
45 void * rcalloc (size_t nmemb, size_t size)
48 if (size == 0) size++;
49 if (nmemb == 0) nmemb++;
50 value = calloc (nmemb, size);
52 value = vmefail(size);
56 void * rrealloc (void *ptr, size_t size)
59 if (size == 0) size++;
60 value = realloc (ptr, size);
62 value = vmefail(size);
66 char * rstrdup (const char *str)
68 size_t size = strlen(str) + 1;
69 char *newstr = (char *) malloc (size);
71 newstr = (char *) vmefail(size);
76 void * rfree (void *ptr)