*/
/*
- * Copyright (C) 2012-2016 Eric Biggers
+ * Copyright 2012-2023 Eric Biggers
*
* This file is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* details.
*
* You should have received a copy of the GNU Lesser General Public License
- * along with this file; if not, see http://www.gnu.org/licenses/.
+ * along with this file; if not, see https://www.gnu.org/licenses/.
*/
#ifdef HAVE_CONFIG_H
#include <errno.h>
#include <fcntl.h>
-#ifndef __WIN32__
-# include <langinfo.h>
-#endif
-#include <pthread.h>
#include <stdlib.h>
+#include <sys/stat.h>
#include <unistd.h>
#include "wimlib.h"
#include "wimlib/assert.h"
#include "wimlib/blob_table.h"
+#include "wimlib/cpu_features.h"
#include "wimlib/dentry.h"
#include "wimlib/encoding.h"
#include "wimlib/file_io.h"
#include "wimlib/integrity.h"
#include "wimlib/metadata.h"
-#include "wimlib/ntfs_3g.h" /* for libntfs3g_global_init() */
#include "wimlib/security.h"
+#include "wimlib/threads.h"
#include "wimlib/wim.h"
#include "wimlib/xml.h"
#include "wimlib/win32.h"
int ret;
WIMStruct *wim;
- ret = wimlib_global_init(WIMLIB_INIT_FLAG_ASSUME_UTF8);
+ ret = wimlib_global_init(0);
if (ret)
return ret;
if (!wim)
return WIMLIB_ERR_NOMEM;
- wim->xml_info = xml_new_info_struct();
- wim->blob_table = new_blob_table(64);
- if (!wim->xml_info || !wim->blob_table) {
- wimlib_free(wim);
- return WIMLIB_ERR_NOMEM;
- }
-
- /* Fill in wim->hdr with default values */
+ /* Fill in wim->hdr with default values */
wim->hdr.magic = WIM_MAGIC;
wim->hdr.wim_version = WIM_VERSION_DEFAULT;
- wim->hdr.flags = 0;
- wim->hdr.chunk_size = 0;
- generate_guid(wim->hdr.guid);
wim->hdr.part_number = 1;
wim->hdr.total_parts = 1;
- wim->hdr.image_count = 0;
- wim->hdr.boot_idx = 0;
-
wim->compression_type = WIMLIB_COMPRESSION_TYPE_NONE;
- wim->chunk_size = wim->hdr.chunk_size;
- /* Set the output compression type */
+ /* Set the output compression type */
wim->out_compression_type = ctype;
wim->out_chunk_size = wim_default_nonsolid_chunk_size(ctype);
+ /* Allocate an empty XML info and blob table */
+ wim->xml_info = xml_new_info_struct();
+ wim->blob_table = new_blob_table(64);
+ if (!wim->xml_info || !wim->blob_table) {
+ wimlib_free(wim);
+ return WIMLIB_ERR_NOMEM;
+ }
+
*wim_ret = wim;
return 0;
}
filedes_init(&wim->in_fd, *(const int*)wim_filename_or_fd);
wim->in_fd.is_pipe = 1;
} else {
+ struct stat stbuf;
+
wimfile = wim_filename_or_fd;
ret = open_wim_file(wimfile, &wim->in_fd);
if (ret)
return ret;
+ /* The file size is needed for enforcing some limits later. */
+ if (fstat(wim->in_fd.fd, &stbuf) == 0)
+ wim->file_size = stbuf.st_size;
+
/* The absolute path to the WIM is requested so that
* wimlib_overwrite() still works even if the process changes
* its working directory. This actually happens if a WIM is
WIMStruct *wim;
int ret;
- ret = wimlib_global_init(WIMLIB_INIT_FLAG_ASSUME_UTF8);
+ ret = wimlib_global_init(0);
if (ret)
return ret;
wim_decrement_refcnt(wim);
}
-static bool
-test_locale_ctype_utf8(void)
-{
-#ifdef __WIN32__
- return false;
-#else
- char *ctype = nl_langinfo(CODESET);
-
- return (strstr(ctype, "UTF-8") ||
- strstr(ctype, "UTF8") ||
- strstr(ctype, "utf8") ||
- strstr(ctype, "utf-8"));
-#endif
-}
-
/* API function documented in wimlib.h */
WIMLIBAPI u32
wimlib_get_version(void)
WIMLIB_PATCH_VERSION;
}
+WIMLIBAPI const tchar *
+wimlib_get_version_string(void)
+{
+ return T(PACKAGE_VERSION);
+}
+
static bool lib_initialized = false;
-static pthread_mutex_t lib_initialization_mutex = PTHREAD_MUTEX_INITIALIZER;
+static struct mutex lib_initialization_mutex = MUTEX_INITIALIZER;
/* API function documented in wimlib.h */
WIMLIBAPI int
if (lib_initialized)
goto out;
- pthread_mutex_lock(&lib_initialization_mutex);
+ mutex_lock(&lib_initialization_mutex);
if (lib_initialized)
goto out_unlock;
-#ifdef ENABLE_ERROR_MESSAGES
if (!wimlib_error_file)
wimlib_error_file = stderr;
-#endif
ret = WIMLIB_ERR_INVALID_PARAM;
if (init_flags & ~(WIMLIB_INIT_FLAG_ASSUME_UTF8 |
WIMLIB_INIT_FLAG_DEFAULT_CASE_INSENSITIVE))
goto out_unlock;
- xml_global_init();
- if (!(init_flags & WIMLIB_INIT_FLAG_ASSUME_UTF8)) {
- wimlib_mbs_is_utf8 = test_locale_ctype_utf8();
- #ifdef WITH_NTFS_3G
- if (!wimlib_mbs_is_utf8)
- libntfs3g_global_init();
- #endif
- }
-#ifdef __WIN32__
+ init_cpu_features();
+#ifdef _WIN32
ret = win32_global_init(init_flags);
if (ret)
goto out_unlock;
#endif
- iconv_global_init();
init_upcase();
if (init_flags & WIMLIB_INIT_FLAG_DEFAULT_CASE_SENSITIVE)
default_ignore_case = false;
lib_initialized = true;
ret = 0;
out_unlock:
- pthread_mutex_unlock(&lib_initialization_mutex);
+ mutex_unlock(&lib_initialization_mutex);
out:
return ret;
}
if (!lib_initialized)
return;
- pthread_mutex_lock(&lib_initialization_mutex);
+ mutex_lock(&lib_initialization_mutex);
if (!lib_initialized)
goto out_unlock;
- xml_global_cleanup();
- iconv_global_cleanup();
-#ifdef __WIN32__
+#ifdef _WIN32
win32_global_cleanup();
#endif
lib_initialized = false;
out_unlock:
- pthread_mutex_unlock(&lib_initialization_mutex);
+ mutex_unlock(&lib_initialization_mutex);
}