X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fwim.c;h=1ffc3fef442dccb5e0760bcd28db5f3cbbd99a31;hp=23858d69b03c538261c64fee25e0db49030442f6;hb=2a33c303e30fd740f740e21632fd06b9e414b0c7;hpb=71ac0d27d857d6de96d231fa41f4008f5654a998 diff --git a/src/wim.c b/src/wim.c index 23858d69..1ffc3fef 100644 --- a/src/wim.c +++ b/src/wim.c @@ -3,7 +3,7 @@ */ /* - * Copyright (C) 2012 Eric Biggers + * Copyright (C) 2012, 2013 Eric Biggers * * wimlib - Library for working with WIM files * @@ -24,6 +24,14 @@ */ #include "config.h" + +#ifdef __WIN32__ +# include +# ifdef ERROR +# undef ERROR +# endif +#endif + #include #include #include @@ -43,6 +51,32 @@ #include "lookup_table.h" #include "xml.h" +#ifdef __WIN32__ +static char *realpath(const char *path, char *resolved_path) +{ + DWORD ret; + wimlib_assert(resolved_path == NULL); + + ret = GetFullPathNameA(path, 0, NULL, NULL); + if (!ret) + goto fail_win32; + + resolved_path = MALLOC(ret + 1); + if (!resolved_path) + goto fail; + ret = GetFullPathNameA(path, ret, resolved_path, NULL); + if (!ret) { + free(resolved_path); + goto fail_win32; + } + return resolved_path; +fail_win32: + win32_error(GetLastError()); +fail: + return NULL; +} +#endif + static int image_print_metadata(WIMStruct *w) { DEBUG("Printing metadata for image %d", w->current_image); @@ -204,6 +238,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); @@ -233,20 +268,21 @@ int select_wim_image(WIMStruct *w, int image) INIT_HLIST_HEAD(&imd->inode_list); } } - w->current_image = image; - imd = wim_get_current_image_metadata(w); - + imd = &w->image_metadata[image - 1]; 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) + w->current_image = WIMLIB_NO_IMAGE; } + return ret; } @@ -597,7 +633,7 @@ void destroy_image_metadata(struct wim_image_metadata *imd, * closes all files associated with the WIMStruct. */ WIMLIBAPI void wimlib_free(WIMStruct *w) { - DEBUG2("Freeing WIMStruct"); + DEBUG("Freeing WIMStruct"); if (!w) return; @@ -633,4 +669,21 @@ WIMLIBAPI void wimlib_free(WIMStruct *w) } #endif FREE(w); + DEBUG("Freed WIMStruct"); +} + +/* 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(); }