]> wimlib.net Git - wimlib/blobdiff - examples/updatewim.c
mount_image.c: add fallback definitions of RENAME_* constants
[wimlib] / examples / updatewim.c
index 910eab11e69eeaa45ce92af30b7d1892e3b2520f..a929886fa21de7ac1f9f2c8ba68e77230cd36af0 100644 (file)
@@ -2,20 +2,56 @@
  * updatewim.c - A program to add a file or directory tree to the first image of
  * a WIM file.
  *
- * The author dedicates this file to the public domain.
- * You can do whatever you want with this 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 <string.h>
 
-int main(int argc, char **argv)
+/*
+ * 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
+
+int main(int argc, tchar **argv)
 {
        int ret;
-       char *wimfile;
-       char *wim_target_path;
-       char *fs_source_path;
+       tchar *wimfile;
+       tchar *wim_target_path;
+       tchar *fs_source_path;
        WIMStruct *wim = NULL;
+       struct wimlib_update_command cmds[1];
 
        /* Check for the correct number of arguments.  */
        if (argc != 4) {
@@ -40,8 +76,6 @@ int main(int argc, char **argv)
         * sake of demonstration we will use the more general function
         * wimlib_update_image().  */
 
-       struct wimlib_update_command cmds[1];
-
        memset(cmds, 0, sizeof(cmds));
 
        /* Set up an "add" operation.
@@ -86,8 +120,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).  */