]> wimlib.net Git - wimlib/blobdiff - src/util.c
Remove verify_dentry(); separate refcnt recalc. from verify_inode()
[wimlib] / src / util.c
index df3b5c8a67cffa70c0dc26258ba2830950d5bf5f..f5a8ca29fb5e6451aea7926a0975471ce10f2514 100644 (file)
@@ -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)
@@ -389,6 +389,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]
@@ -407,9 +409,33 @@ wimlib_get_error_string(enum wimlib_error_code code)
 
 
 #ifdef ENABLE_CUSTOM_MEMORY_ALLOCATOR
-void *(*wimlib_malloc_func) (size_t)        = malloc;
-void  (*wimlib_free_func)   (void *)        = free;
-void *(*wimlib_realloc_func)(void *, size_t) = realloc;
+static void *(*wimlib_malloc_func) (size_t)         = malloc;
+static void  (*wimlib_free_func)   (void *)         = free;
+static void *(*wimlib_realloc_func)(void *, size_t) = realloc;
+
+void *
+wimlib_malloc(size_t size)
+{
+       void *ptr = (*wimlib_malloc_func)(size);
+       if (ptr == NULL && size != 0)
+               ERROR("memory exhausted");
+       return ptr;
+}
+
+void
+wimlib_free_memory(void *ptr)
+{
+       (*wimlib_free_func)(ptr);
+}
+
+void *
+wimlib_realloc(void *ptr, size_t 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)
@@ -417,7 +443,7 @@ wimlib_calloc(size_t nmemb, size_t size)
        size_t total_size = nmemb * size;
        void *p = MALLOC(total_size);
        if (p)
-               memset(p, 0, total_size);
+               p = memset(p, 0, total_size);
        return p;
 }
 
@@ -430,7 +456,7 @@ wimlib_strdup(const char *str)
        size = strlen(str);
        p = MALLOC(size + 1);
        if (p)
-               memcpy(p, str, size + 1);
+               p = memcpy(p, str, size + 1);
        return p;
 }
 
@@ -444,13 +470,22 @@ wimlib_wcsdup(const wchar_t *str)
        size = wcslen(str);
        p = MALLOC((size + 1) * sizeof(wchar_t));
        if (p)
-               memcpy(p, str, (size + 1) * sizeof(wchar_t));
+               p = wmemcpy(p, str, size + 1);
        return p;
 }
 #endif
 
 #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 *),