Add calls to wimlib_global_init()
authorEric Biggers <ebiggers3@gmail.com>
Thu, 23 May 2013 04:27:35 +0000 (23:27 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Thu, 23 May 2013 04:30:16 +0000 (23:30 -0500)
... in wimlib_open_wim() and wimlib_create_new_wim(), just in case the library
user did not explicitly call wimlib_global_init() (otherwise this could cause
problems on Windows, with the Windows version not being determined).

src/wim.c

index 2a3c08c..b15a02d 100644 (file)
--- a/src/wim.c
+++ b/src/wim.c
@@ -125,6 +125,8 @@ wimlib_create_new_wim(int ctype, WIMStruct **w_ret)
        struct wim_lookup_table *table;
        int ret;
 
+       wimlib_global_init(WIMLIB_INIT_FLAG_ASSUME_UTF8);
+
        DEBUG("Creating new WIM with %"TS" compression.",
              wimlib_get_compression_type_string(ctype));
 
@@ -634,6 +636,8 @@ wimlib_open_wim(const tchar *wim_file, int open_flags,
        WIMStruct *wim;
        int ret;
 
+       wimlib_global_init(WIMLIB_INIT_FLAG_ASSUME_UTF8);
+
        ret = WIMLIB_ERR_INVALID_PARAM;
        if (!wim_file || !wim_ret)
                goto out;
@@ -880,6 +884,10 @@ test_locale_ctype_utf8(void)
 WIMLIBAPI int
 wimlib_global_init(int init_flags)
 {
+       static bool already_inited = false;
+
+       if (already_inited)
+               return 0;
        libxml_global_init();
        if (!(init_flags & WIMLIB_INIT_FLAG_ASSUME_UTF8)) {
                wimlib_mbs_is_utf8 = test_locale_ctype_utf8();
@@ -891,6 +899,7 @@ wimlib_global_init(int init_flags)
 #ifdef __WIN32__
        win32_global_init();
 #endif
+       already_inited = true;
        return 0;
 }