void *
wimlib_malloc(size_t size)
{
- return (*wimlib_malloc_func)(size);
+ void *ptr = (*wimlib_malloc_func)(size);
+ if (ptr == NULL && size != 0)
+ ERROR("memory exhausted");
+ return ptr;
}
void
void *
wimlib_realloc(void *ptr, size_t size)
{
- return (*wimlib_realloc_func)(ptr, size);
+ ptr = (*wimlib_realloc_func)(ptr, size);
+ if (ptr == NULL && size != 0)
+ ERROR("memory exhausted");
+ return ptr;
}
void *
#endif /* ENABLE_CUSTOM_MEMORY_ALLOCATOR */
+void *
+memdup(const void *mem, size_t size)
+{
+ void *ptr = MALLOC(size);
+ if (ptr)
+ ptr = memcpy(ptr, mem, size);
+ return ptr;
+}
+
WIMLIBAPI int
wimlib_set_memory_allocator(void *(*malloc_func)(size_t),
void (*free_func)(void *),