+
+ if (filedes_valid(&wim->in_fd))
+ filedes_close(&wim->in_fd);
+ if (filedes_valid(&wim->out_fd))
+ filedes_close(&wim->out_fd);
+
+ wimlib_lzx_free_context(wim->lzx_context);
+
+ free_lookup_table(wim->lookup_table);
+
+ FREE(wim->filename);
+ free_wim_info(wim->wim_info);
+ if (wim->image_metadata) {
+ for (unsigned i = 0; i < wim->hdr.image_count; i++)
+ put_image_metadata(wim->image_metadata[i], NULL);
+ FREE(wim->image_metadata);
+ }
+ FREE(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 int
+wimlib_global_init(int init_flags)
+{
+ static bool already_inited = false;
+ int ret;
+
+ if (already_inited)
+ return 0;
+ libxml_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