Created
April 2, 2014 21:42
-
-
Save jcpowermac/9943787 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /*** | |
| * | |
| * Code from: http://sourceforge.net/p/wimlib/code/ci/master/tree/programs/imagex.c | |
| * http://sourceforge.net/p/wimlib/code/ci/master/tree/src/xml.c | |
| */ | |
| #include <wimlib.h> | |
| #include <wimlib_tchar.h> | |
| #include <ctype.h> | |
| #include <errno.h> | |
| #include <wimlib.h> | |
| #include <wimlib_tchar.h> | |
| #include <inttypes.h> | |
| #include <libgen.h> | |
| #include <limits.h> | |
| #include <stdarg.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <sys/stat.h> | |
| #include <unistd.h> | |
| #include <locale.h> | |
| //static bool imagex_be_quiet = false; | |
| //static FILE *imagex_info_file; | |
| /* | |
| static int imagex_progress_func(enum wimlib_progress_msg msg, | |
| const union wimlib_progress_info *info); | |
| */ | |
| //static struct wimlib_progress_info_scan last_scan_progress; | |
| #define imagex_printf(format, ...) \ | |
| tfprintf(imagex_info_file, format, ##__VA_ARGS__) | |
| #define TO_PERCENT(numerator, denominator) \ | |
| (((denominator) == 0) ? 0 : ((numerator) * 100 / (denominator))) | |
| #define GIBIBYTE_MIN_NBYTES 10000000000ULL | |
| #define MEBIBYTE_MIN_NBYTES 10000000ULL | |
| #define KIBIBYTE_MIN_NBYTES 10000ULL | |
| int main() { | |
| const tchar *wimfile = "/mnt/iso/sources/install.wim"; | |
| WIMStruct *wim; | |
| int ret; | |
| int open_flags = 0; | |
| struct wimlib_wim_info info; | |
| size_t bufsize_ret; | |
| void *buffer; | |
| char *return_data; | |
| ret = wimlib_open_wim(wimfile, open_flags, &wim, NULL ); | |
| if (ret) | |
| goto out; | |
| ret = wimlib_get_wim_info(wim, &info); | |
| ret = wimlib_get_xml_data(wim, &buffer, &bufsize_ret); | |
| if ((return_data = malloc(bufsize_ret)) == NULL ) { | |
| printf("uh oh"); | |
| exit(1); | |
| } | |
| int i; | |
| for (i = 0; i < bufsize_ret; i++) { | |
| const char *ptr_char_array = (const char*) &buffer[i]; | |
| /* | |
| * Get rid of the ugly chars | |
| */ | |
| if (ptr_char_array[0] > 0 && ptr_char_array[0] < 256) { | |
| strncat(return_data, ptr_char_array, 1); | |
| } | |
| } | |
| printf("%s", return_data); | |
| free(return_data); | |
| if (ret) | |
| goto out_wimlib_free; | |
| out_wimlib_free: wimlib_free(wim); | |
| out: printf("when out - %d\n", ret); | |
| return ret; | |
| out_err: ret = -1; | |
| goto out; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment