X-Git-Url: https://wimlib.net/git/?a=blobdiff_plain;f=src%2Futil.c;h=08bcb39b70f4037211fa19e88a6b0526144c158f;hb=87345050a103f26b8bd4be4b26f26e2931345317;hp=f7ed251c784868028bf12ef2be01cd36221738d8;hpb=f3ab01445d6184f7c5ffd0251667de7ef7437f9a;p=wimlib diff --git a/src/util.c b/src/util.c index f7ed251c..08bcb39b 100644 --- a/src/util.c +++ b/src/util.c @@ -145,7 +145,7 @@ wimlib_fprintf(FILE *fp, const tchar *format, ...) #endif /* __WIN32__ */ #ifdef ENABLE_ERROR_MESSAGES -static bool wimlib_print_errors = false; +bool wimlib_print_errors = false; #endif #if defined(ENABLE_ERROR_MESSAGES) || defined(ENABLE_DEBUG) @@ -369,6 +369,8 @@ static const tchar *error_strings[] = { = T("Could not rename a file"), [WIMLIB_ERR_REPARSE_POINT_FIXUP_FAILED] = T("Unable to complete reparse point fixup"), + [WIMLIB_ERR_RESOURCE_NOT_FOUND] + = T("A file resource needed to complete the operation was missing from the WIM"), [WIMLIB_ERR_RESOURCE_ORDER] = T("The components of the WIM were arranged in an unexpected order"), [WIMLIB_ERR_SPECIAL_FILE] @@ -389,6 +391,8 @@ static const tchar *error_strings[] = { = T("The requested operation is unsupported"), [WIMLIB_ERR_VOLUME_LACKS_FEATURES] = T("The volume did not support a feature necessary to complete the operation"), + [WIMLIB_ERR_WIM_IS_READONLY] + = T("The WIM is read-only (file permissions, header flag, or split WIM)"), [WIMLIB_ERR_WRITE] = T("Failed to write data to a file"), [WIMLIB_ERR_XML] @@ -414,7 +418,10 @@ static void *(*wimlib_realloc_func)(void *, size_t) = realloc; 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 @@ -426,14 +433,17 @@ wimlib_free_memory(void *ptr) 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 * wimlib_calloc(size_t nmemb, size_t size) { size_t total_size = nmemb * size; - void *p = (*wimlib_malloc_func)(total_size); + void *p = MALLOC(total_size); if (p) p = memset(p, 0, total_size); return p; @@ -446,9 +456,9 @@ wimlib_strdup(const char *str) char *p; size = strlen(str); - p = (*wimlib_malloc_func)(size + 1); + p = MALLOC(size + 1); if (p) - memcpy(p, str, size + 1); + p = memcpy(p, str, size + 1); return p; } @@ -460,7 +470,7 @@ wimlib_wcsdup(const wchar_t *str) wchar_t *p; size = wcslen(str); - p = (*wimlib_malloc_func)((size + 1) * sizeof(wchar_t)); + p = MALLOC((size + 1) * sizeof(wchar_t)); if (p) p = wmemcpy(p, str, size + 1); return p; @@ -469,6 +479,15 @@ wimlib_wcsdup(const wchar_t *str) #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 *),