]> wimlib.net Git - wimlib/blobdiff - examples/applywim.c
v1.14.4
[wimlib] / examples / applywim.c
index d6873167ab5aeea376b68a02cc2508d8cbf608fc..ef65ba1bb9b0b4b41ff07518c75570a92b7cf746 100644 (file)
@@ -1,10 +1,48 @@
 /*
  * applywim.c - A program to extract the first image from a WIM file.
 /*
  * applywim.c - A program to extract the first image from a WIM file.
+ *
+ * Copyright 2022 Eric Biggers
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 #include <wimlib.h>
 #include <stdio.h>
 
  */
 
 #include <wimlib.h>
 #include <stdio.h>
 
+/*
+ * Windows compatibility defines for string encoding.  Applications using wimlib
+ * that need to run on both UNIX and Windows will need to do something similar
+ * to this, whereas applications that only need to run on one or the other can
+ * just use their platform's convention directly.
+ */
+#ifdef _WIN32
+#  define main         wmain
+   typedef wchar_t     tchar;
+#  define TS           "ls"
+#else
+   typedef char                tchar;
+#  define TS           "s"
+#endif
+
 #define TO_PERCENT(numerator, denominator) \
        ((float)(((denominator) == 0) ? 0 : ((numerator) * 100 / (float)(denominator))))
 
 #define TO_PERCENT(numerator, denominator) \
        ((float)(((denominator) == 0) ? 0 : ((numerator) * 100 / (float)(denominator))))
 
@@ -24,12 +62,12 @@ extract_progress(enum wimlib_progress_msg msg,
        return WIMLIB_PROGRESS_STATUS_CONTINUE;
 }
 
        return WIMLIB_PROGRESS_STATUS_CONTINUE;
 }
 
-int main(int argc, char **argv)
+int main(int argc, tchar **argv)
 {
        int ret;
        WIMStruct *wim = NULL;
 {
        int ret;
        WIMStruct *wim = NULL;
-       const char *wimpath;
-       const char *destdir;
+       const tchar *wimpath;
+       const tchar *destdir;
 
        /* Check for the correct number of arguments.  */
        if (argc != 3) {
 
        /* Check for the correct number of arguments.  */
        if (argc != 3) {
@@ -62,8 +100,8 @@ out:
 
        /* Check for error status.  */
        if (ret != 0) {
 
        /* Check for error status.  */
        if (ret != 0) {
-               fprintf(stderr, "wimlib error %d: %s\n",
-                       ret, wimlib_get_error_string(ret));
+               fprintf(stderr, "wimlib error %d: %" TS"\n",
+                       ret, wimlib_get_error_string((enum wimlib_error_code)ret));
        }
 
        /* Free global memory (optional).  */
        }
 
        /* Free global memory (optional).  */