Patch from Aurelien Jacobs to add unlzma. (A new decompression type,
[oweals/busybox.git] / archival / libunarchive / get_header_cpio.c
index 25fdc060064b9d9f4f62bc69ee3037a1bb76bf17..11925c4e3e2b648aeab22734af6c1f50ced79328 100644 (file)
@@ -18,6 +18,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/sysmacros.h>     /* major() and minor() */
 #include "unarchive.h"
 #include "libbb.h"
 
@@ -36,7 +37,7 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
        int namesize;
        char dummy[16];
        int major, minor, nlink, inode;
-       
+
        if (pending_hardlinks) { /* Deal with any pending hardlinks */
                hardlinks_t *tmp;
                hardlinks_t *oldtmp;
@@ -77,7 +78,7 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
        {
            unsigned long tmpsize;
            sscanf(cpio_header, "%6c%8x%8x%8x%8x%8x%8lx%8lx%16c%8x%8x%8x%8c",
-                   dummy, &inode, (unsigned int*)&file_header->mode, 
+                   dummy, &inode, (unsigned int*)&file_header->mode,
                    (unsigned int*)&file_header->uid, (unsigned int*)&file_header->gid,
                    &nlink, &file_header->mtime, &tmpsize,
                    dummy, &major, &minor, &namesize, dummy);
@@ -117,6 +118,8 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
                file_header->link_name[file_header->size] = '\0';
                archive_handle->offset += file_header->size;
                file_header->size = 0; /* Stop possible seeks in future */
+       } else {
+               file_header->link_name = NULL;
        }
        if (nlink > 1 && !S_ISDIR(file_header->mode)) {
                if (file_header->size == 0) { /* Put file on a linked list for later */
@@ -141,15 +144,18 @@ extern char get_header_cpio(archive_handle_t *archive_handle)
                        }
                }
        }
-       file_header->device = (major << 8) | minor;
+       file_header->device = makedev(major, minor);
 
        if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) {
                archive_handle->action_data(archive_handle);
                archive_handle->action_header(archive_handle->file_header);
        } else {
-               data_skip(archive_handle);                      
+               data_skip(archive_handle);
        }
 
        archive_handle->offset += file_header->size;
+
+       free(file_header->link_name);
+
        return (EXIT_SUCCESS);
 }