]> wimlib.net Git - wimlib/blobdiff - examples/applywim.c
examples: C++ and Windows compatibility
[wimlib] / examples / applywim.c
index ffcff1496305c699461a6f3f3f66be52a35ff42c..cd6d340967ee4fca79029a3f1ae654884254f86b 100644 (file)
@@ -3,7 +3,7 @@
  *
  * The following copying information applies to this specific source code file:
  *
- * Written in 2013-2014 by Eric Biggers <ebiggers3@gmail.com>
+ * Written in 2013-2016 by Eric Biggers <ebiggers3@gmail.com>
  *
  * To the extent possible under law, the author(s) have dedicated all copyright
  * and related and neighboring rights to this software to the public domain
 #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))))
 
@@ -40,12 +55,12 @@ extract_progress(enum wimlib_progress_msg msg,
        return WIMLIB_PROGRESS_STATUS_CONTINUE;
 }
 
-int main(int argc, char **argv)
+int main(int argc, tchar **argv)
 {
        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) {
@@ -78,8 +93,8 @@ out:
 
        /* 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).  */