]> wimlib.net Git - wimlib/blobdiff - src/extract.c
util.h: gcc printf format attribute
[wimlib] / src / extract.c
index 7dd957cc908cf4499ff8f054be3d4f03b269e76f..8873683f48302efbbeebb5bd7ef92ae0e4ae5595 100644 (file)
@@ -2,24 +2,26 @@
  * extract.c
  *
  * Support for extracting WIM files.
- *
+ */
+
+/*
  * Copyright (C) 2010 Carl Thijssen
  * Copyright (C) 2012 Eric Biggers
  *
- * wimlib - Library for working with WIM files 
+ * This file is part of wimlib, a library for working with WIM files.
  *
- * This library is free software; you can redistribute it and/or modify it under
- * the terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 2.1 of the License, or (at your option) any
- * later version.
+ * wimlib is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation; either version 2.1 of the License, or (at your option)
+ * any later version.
  *
- * This library is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ * A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
+ * details.
  *
- * You should have received a copy of the GNU Lesser General Public License along
- * with this library; if not, write to the Free Software Foundation, Inc., 59
- * Temple Place, Suite 330, Boston, MA 02111-1307 USA 
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with wimlib; if not, see http://www.gnu.org/licenses/.
  */
 
 #include "wimlib_internal.h"
@@ -239,11 +241,12 @@ static int extract_single_image(WIMStruct *w, int image)
  * subdirectories named by their image names. */
 static int extract_all_images(WIMStruct *w)
 {
-       size_t image_name_max_len = xml_get_max_image_name_len(w);
+       size_t image_name_max_len = max(xml_get_max_image_name_len(w), 20);
        size_t output_path_len = strlen(w->output_dir);
        char buf[output_path_len + 1 + image_name_max_len + 1];
        int ret;
        int image;
+       const char *image_name;
 
        DEBUG("Attempting to extract all images from `%s'\n", w->filename);
 
@@ -251,8 +254,15 @@ static int extract_all_images(WIMStruct *w)
        buf[output_path_len] = '/';
        for (image = 1; image <= w->hdr.image_count; image++) {
                buf[output_path_len + 1] = '\0';
-               strncat(buf + output_path_len + 1, wimlib_get_image_name(w, image),
+               
+               image_name = wimlib_get_image_name(w, image);
+               if (*image_name) {
+                       strncat(buf + output_path_len + 1, image_name, 
                                image_name_max_len);
+               } else {
+                       /* Image name is empty. Use image number instead */
+                       sprintf(buf + output_path_len + 1, "%d", image);
+               }
                ret = wimlib_set_output_dir(w, buf);
                if (ret != 0)
                        goto done;