X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fwim.c;h=e1698952e0f5c889ca9ff8bbb6449a223ad5d536;hp=23858d69b03c538261c64fee25e0db49030442f6;hb=2e698d082750987ba1734beb8b1934efec1d9856;hpb=71ac0d27d857d6de96d231fa41f4008f5654a998 diff --git a/src/wim.c b/src/wim.c index 23858d69..e1698952 100644 --- a/src/wim.c +++ b/src/wim.c @@ -204,6 +204,7 @@ WIMLIBAPI int wimlib_get_num_images(const WIMStruct *w) int select_wim_image(WIMStruct *w, int image) { struct wim_image_metadata *imd; + int ret; DEBUG("Selecting image %d", image); @@ -232,21 +233,23 @@ int select_wim_image(WIMStruct *w, int image) imd->security_data = NULL; INIT_HLIST_HEAD(&imd->inode_list); } + w->current_image = WIMLIB_NO_IMAGE; } - w->current_image = image; imd = wim_get_current_image_metadata(w); - if (imd->root_dentry) { - return 0; + ret = 0; } else { #ifdef ENABLE_DEBUG DEBUG("Reading metadata resource specified by the following " "lookup table entry:"); - print_lookup_table_entry(imd->metadata_lte); + print_lookup_table_entry(imd->metadata_lte, stdout); #endif - return read_metadata_resource(w, imd); + ret = read_metadata_resource(w, imd); } + if (ret == 0) + w->current_image = image; + return ret; } @@ -634,3 +637,19 @@ WIMLIBAPI void wimlib_free(WIMStruct *w) #endif FREE(w); } + +/* Get global memory allocations out of the way. Not strictly necessary in + * single-threaded programs like 'imagex'. */ +WIMLIBAPI int wimlib_global_init() +{ + libxml_global_init(); + return iconv_global_init(); +} + +/* Free global memory allocations. Not strictly necessary if the process using + * wimlib is just about to exit (as is the case for 'imagex'). */ +WIMLIBAPI void wimlib_global_cleanup() +{ + libxml_global_cleanup(); + iconv_global_cleanup(); +}