aboutsummaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-08 12:49:22 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-08 12:49:22 +0000
commit1385899416a4396385ad421ae1f532be7103738a (patch)
treefc4d14a910593d1235318bb36abe5e9f72d2039e /archival
parent5625415085e68ac5e150f54e685417c866620d76 (diff)
downloadbusybox-w32-1385899416a4396385ad421ae1f532be7103738a.tar.gz
busybox-w32-1385899416a4396385ad421ae1f532be7103738a.tar.bz2
busybox-w32-1385899416a4396385ad421ae1f532be7103738a.zip
attempt to regularize atoi mess.
Diffstat (limited to 'archival')
-rw-r--r--archival/cpio.c2
-rw-r--r--archival/libunarchive/Kbuild2
-rw-r--r--archival/libunarchive/get_header_ar.c12
-rw-r--r--archival/libunarchive/get_header_tar.c45
-rw-r--r--archival/libunarchive/get_header_tar_bz2.c6
-rw-r--r--archival/libunarchive/get_header_tar_gz.c6
-rw-r--r--archival/libunarchive/get_header_tar_lzma.c5
-rw-r--r--archival/libunarchive/seek_by_jump.c2
-rw-r--r--archival/libunarchive/seek_by_read.c (renamed from archival/libunarchive/seek_by_char.c)8
-rw-r--r--archival/rpm.c2
-rw-r--r--archival/tar.c4
-rw-r--r--archival/unzip.c11
12 files changed, 50 insertions, 55 deletions
diff --git a/archival/cpio.c b/archival/cpio.c
index d0d3288ff..751e87952 100644
--- a/archival/cpio.c
+++ b/archival/cpio.c
@@ -35,7 +35,7 @@ int cpio_main(int argc, char **argv)
35 /* Initialise */ 35 /* Initialise */
36 archive_handle = init_handle(); 36 archive_handle = init_handle();
37 archive_handle->src_fd = STDIN_FILENO; 37 archive_handle->src_fd = STDIN_FILENO;
38 archive_handle->seek = seek_by_char; 38 archive_handle->seek = seek_by_read;
39 archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE; 39 archive_handle->flags = ARCHIVE_EXTRACT_NEWER | ARCHIVE_PRESERVE_DATE;
40 40
41 opt = getopt32(argc, argv, "ituvF:dm", &cpio_filename); 41 opt = getopt32(argc, argv, "ituvF:dm", &cpio_filename);
diff --git a/archival/libunarchive/Kbuild b/archival/libunarchive/Kbuild
index c5f1bfbfe..4e1454184 100644
--- a/archival/libunarchive/Kbuild
+++ b/archival/libunarchive/Kbuild
@@ -21,7 +21,7 @@ lib-y:= \
21\ 21\
22 archive_xread_all_eof.o \ 22 archive_xread_all_eof.o \
23\ 23\
24 seek_by_char.o \ 24 seek_by_read.o \
25 seek_by_jump.o \ 25 seek_by_jump.o \
26\ 26\
27 data_align.o \ 27 data_align.o \
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c
index cabb4101b..7372ada32 100644
--- a/archival/libunarchive/get_header_ar.c
+++ b/archival/libunarchive/get_header_ar.c
@@ -46,14 +46,14 @@ char get_header_ar(archive_handle_t *archive_handle)
46 46
47 /* align the headers based on the header magic */ 47 /* align the headers based on the header magic */
48 if ((ar.formatted.magic[0] != '`') || (ar.formatted.magic[1] != '\n')) { 48 if ((ar.formatted.magic[0] != '`') || (ar.formatted.magic[1] != '\n')) {
49 bb_error_msg_and_die("Invalid ar header"); 49 bb_error_msg_and_die("invalid ar header");
50 } 50 }
51 51
52 typed->mode = strtol(ar.formatted.mode, NULL, 8); 52 typed->mode = xstrtoul(ar.formatted.mode, 8);
53 typed->mtime = atoi(ar.formatted.date); 53 typed->mtime = xatou(ar.formatted.date);
54 typed->uid = atoi(ar.formatted.uid); 54 typed->uid = xatou(ar.formatted.uid);
55 typed->gid = atoi(ar.formatted.gid); 55 typed->gid = xatou(ar.formatted.gid);
56 typed->size = atoi(ar.formatted.size); 56 typed->size = xatoul(ar.formatted.size);
57 57
58 /* long filenames have '/' as the first character */ 58 /* long filenames have '/' as the first character */
59 if (ar.formatted.name[0] == '/') { 59 if (ar.formatted.name[0] == '/') {
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c
index 0c622f44a..d3cd96d0c 100644
--- a/archival/libunarchive/get_header_tar.c
+++ b/archival/libunarchive/get_header_tar.c
@@ -62,10 +62,10 @@ char get_header_tar(archive_handle_t *archive_handle)
62 * Read until the end to empty the pipe from gz or bz2 62 * Read until the end to empty the pipe from gz or bz2
63 */ 63 */
64 while (full_read(archive_handle->src_fd, tar.raw, 512) == 512); 64 while (full_read(archive_handle->src_fd, tar.raw, 512) == 512);
65 return(EXIT_FAILURE); 65 return EXIT_FAILURE;
66 } 66 }
67 end = 1; 67 end = 1;
68 return(EXIT_SUCCESS); 68 return EXIT_SUCCESS;
69 } 69 }
70 end = 0; 70 end = 0;
71 71
@@ -76,19 +76,18 @@ char get_header_tar(archive_handle_t *archive_handle)
76#ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY 76#ifdef CONFIG_FEATURE_TAR_OLDGNU_COMPATIBILITY
77 if (strncmp(tar.formatted.magic, "\0\0\0\0\0", 5) != 0) 77 if (strncmp(tar.formatted.magic, "\0\0\0\0\0", 5) != 0)
78#endif 78#endif
79 bb_error_msg_and_die("Invalid tar magic"); 79 bb_error_msg_and_die("invalid tar magic");
80 } 80 }
81 /* Do checksum on headers */ 81 /* Do checksum on headers */
82 for (i = 0; i < 148 ; i++) { 82 for (i = 0; i < 148 ; i++) {
83 sum += tar.raw[i]; 83 sum += tar.raw[i];
84 } 84 }
85 sum += ' ' * 8; 85 sum += ' ' * 8;
86 for (i = 156; i < 512 ; i++) { 86 for (i = 156; i < 512 ; i++) {
87 sum += tar.raw[i]; 87 sum += tar.raw[i];
88 } 88 }
89 if (sum != strtol(tar.formatted.chksum, NULL, 8)) { 89 if (sum != xstrtoul(tar.formatted.chksum, 8)) {
90 bb_error_msg("Invalid tar header checksum"); 90 bb_error_msg_and_die("invalid tar header checksum");
91 return(EXIT_FAILURE);
92 } 91 }
93 92
94#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS 93#ifdef CONFIG_FEATURE_TAR_GNU_EXTENSIONS
@@ -102,8 +101,7 @@ char get_header_tar(archive_handle_t *archive_handle)
102 } else 101 } else
103#endif 102#endif
104 { 103 {
105 file_header->name = xstrndup(tar.formatted.name,100); 104 file_header->name = xstrndup(tar.formatted.name, 100);
106
107 if (tar.formatted.prefix[0]) { 105 if (tar.formatted.prefix[0]) {
108 char *temp = file_header->name; 106 char *temp = file_header->name;
109 file_header->name = concat_path_file(tar.formatted.prefix, temp); 107 file_header->name = concat_path_file(tar.formatted.prefix, temp);
@@ -111,17 +109,18 @@ char get_header_tar(archive_handle_t *archive_handle)
111 } 109 }
112 } 110 }
113 111
114 file_header->uid = strtol(tar.formatted.uid, NULL, 8); 112 file_header->uid = xstrtoul(tar.formatted.uid, 8);
115 file_header->gid = strtol(tar.formatted.gid, NULL, 8); 113 file_header->gid = xstrtoul(tar.formatted.gid, 8);
116 file_header->size = strtol(tar.formatted.size, NULL, 8); 114 // TODO: LFS support
117 file_header->mtime = strtol(tar.formatted.mtime, NULL, 8); 115 file_header->size = xstrtoul(tar.formatted.size, 8);
118 file_header->link_name = (tar.formatted.linkname[0] != '\0') ? 116 file_header->mtime = xstrtoul(tar.formatted.mtime, 8);
119 xstrdup(tar.formatted.linkname) : NULL; 117 file_header->link_name = tar.formatted.linkname[0] ?
120 file_header->device = makedev(strtol(tar.formatted.devmajor, NULL, 8), 118 xstrdup(tar.formatted.linkname) : NULL;
121 strtol(tar.formatted.devminor, NULL, 8)); 119 file_header->device = makedev(xstrtoul(tar.formatted.devmajor, 8),
120 xstrtoul(tar.formatted.devminor, 8));
122 121
123 /* Set bits 0-11 of the files mode */ 122 /* Set bits 0-11 of the files mode */
124 file_header->mode = 07777 & strtol(tar.formatted.mode, NULL, 8); 123 file_header->mode = 07777 & xstrtoul(tar.formatted.mode, 8);
125 124
126 /* Set bits 12-15 of the files mode */ 125 /* Set bits 12-15 of the files mode */
127 switch (tar.formatted.typeflag) { 126 switch (tar.formatted.typeflag) {
@@ -161,7 +160,7 @@ char get_header_tar(archive_handle_t *archive_handle)
161 xread(archive_handle->src_fd, longname, file_header->size); 160 xread(archive_handle->src_fd, longname, file_header->size);
162 archive_handle->offset += file_header->size; 161 archive_handle->offset += file_header->size;
163 162
164 return(get_header_tar(archive_handle)); 163 return get_header_tar(archive_handle);
165 } 164 }
166 case 'K': { 165 case 'K': {
167 linkname = xzalloc(file_header->size + 1); 166 linkname = xzalloc(file_header->size + 1);
@@ -169,7 +168,7 @@ char get_header_tar(archive_handle_t *archive_handle)
169 archive_handle->offset += file_header->size; 168 archive_handle->offset += file_header->size;
170 169
171 file_header->name = linkname; 170 file_header->name = linkname;
172 return(get_header_tar(archive_handle)); 171 return get_header_tar(archive_handle);
173 } 172 }
174 case 'D': /* GNU dump dir */ 173 case 'D': /* GNU dump dir */
175 case 'M': /* Continuation of multi volume archive*/ 174 case 'M': /* Continuation of multi volume archive*/
@@ -179,10 +178,10 @@ char get_header_tar(archive_handle_t *archive_handle)
179#endif 178#endif
180 case 'g': /* pax global header */ 179 case 'g': /* pax global header */
181 case 'x': /* pax extended header */ 180 case 'x': /* pax extended header */
182 bb_error_msg("Ignoring extension type %c", tar.formatted.typeflag); 181 bb_error_msg("ignoring extension type %c", tar.formatted.typeflag);
183 break; 182 break;
184 default: 183 default:
185 bb_error_msg("Unknown typeflag: 0x%x", tar.formatted.typeflag); 184 bb_error_msg("unknown typeflag: 0x%x", tar.formatted.typeflag);
186 } 185 }
187 { /* Strip trailing '/' in directories */ 186 { /* Strip trailing '/' in directories */
188 /* Must be done after mode is set as '/' is used to check if its a directory */ 187 /* Must be done after mode is set as '/' is used to check if its a directory */
@@ -204,5 +203,5 @@ char get_header_tar(archive_handle_t *archive_handle)
204 203
205 free(file_header->link_name); 204 free(file_header->link_name);
206 205
207 return(EXIT_SUCCESS); 206 return EXIT_SUCCESS;
208} 207}
diff --git a/archival/libunarchive/get_header_tar_bz2.c b/archival/libunarchive/get_header_tar_bz2.c
index a8b630814..e3cb328fc 100644
--- a/archival/libunarchive/get_header_tar_bz2.c
+++ b/archival/libunarchive/get_header_tar_bz2.c
@@ -16,12 +16,12 @@
16char get_header_tar_bz2(archive_handle_t *archive_handle) 16char get_header_tar_bz2(archive_handle_t *archive_handle)
17{ 17{
18 /* Cant lseek over pipe's */ 18 /* Cant lseek over pipe's */
19 archive_handle->seek = seek_by_char; 19 archive_handle->seek = seek_by_read;
20 20
21 archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompressStream); 21 archive_handle->src_fd = open_transformer(archive_handle->src_fd, uncompressStream);
22 archive_handle->offset = 0; 22 archive_handle->offset = 0;
23 while (get_header_tar(archive_handle) == EXIT_SUCCESS); 23 while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
24 24
25 /* Can only do one file at a time */ 25 /* Can only do one file at a time */
26 return(EXIT_FAILURE); 26 return EXIT_FAILURE;
27} 27}
diff --git a/archival/libunarchive/get_header_tar_gz.c b/archival/libunarchive/get_header_tar_gz.c
index 24e4f9c9f..af059a187 100644
--- a/archival/libunarchive/get_header_tar_gz.c
+++ b/archival/libunarchive/get_header_tar_gz.c
@@ -13,7 +13,7 @@ char get_header_tar_gz(archive_handle_t *archive_handle)
13 unsigned char magic[2]; 13 unsigned char magic[2];
14 14
15 /* Cant lseek over pipe's */ 15 /* Cant lseek over pipe's */
16 archive_handle->seek = seek_by_char; 16 archive_handle->seek = seek_by_read;
17 17
18 xread(archive_handle->src_fd, &magic, 2); 18 xread(archive_handle->src_fd, &magic, 2);
19 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) { 19 if ((magic[0] != 0x1f) || (magic[1] != 0x8b)) {
@@ -24,8 +24,8 @@ char get_header_tar_gz(archive_handle_t *archive_handle)
24 24
25 archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip); 25 archive_handle->src_fd = open_transformer(archive_handle->src_fd, inflate_gunzip);
26 archive_handle->offset = 0; 26 archive_handle->offset = 0;
27 while (get_header_tar(archive_handle) == EXIT_SUCCESS); 27 while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
28 28
29 /* Can only do one file at a time */ 29 /* Can only do one file at a time */
30 return(EXIT_FAILURE); 30 return EXIT_FAILURE;
31} 31}
diff --git a/archival/libunarchive/get_header_tar_lzma.c b/archival/libunarchive/get_header_tar_lzma.c
index e38583fef..06b8daa0f 100644
--- a/archival/libunarchive/get_header_tar_lzma.c
+++ b/archival/libunarchive/get_header_tar_lzma.c
@@ -11,13 +11,12 @@
11char get_header_tar_lzma(archive_handle_t * archive_handle) 11char get_header_tar_lzma(archive_handle_t * archive_handle)
12{ 12{
13 /* Can't lseek over pipes */ 13 /* Can't lseek over pipes */
14 archive_handle->seek = seek_by_char; 14 archive_handle->seek = seek_by_read;
15 15
16 archive_handle->src_fd = open_transformer(archive_handle->src_fd, unlzma); 16 archive_handle->src_fd = open_transformer(archive_handle->src_fd, unlzma);
17 archive_handle->offset = 0; 17 archive_handle->offset = 0;
18 while (get_header_tar(archive_handle) == EXIT_SUCCESS); 18 while (get_header_tar(archive_handle) == EXIT_SUCCESS) /**/;
19 19
20 /* Can only do one file at a time */ 20 /* Can only do one file at a time */
21 return EXIT_FAILURE; 21 return EXIT_FAILURE;
22} 22}
23
diff --git a/archival/libunarchive/seek_by_jump.c b/archival/libunarchive/seek_by_jump.c
index 231360fa3..e1917dd2a 100644
--- a/archival/libunarchive/seek_by_jump.c
+++ b/archival/libunarchive/seek_by_jump.c
@@ -16,7 +16,7 @@ void seek_by_jump(const archive_handle_t *archive_handle, const unsigned int amo
16 if (lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1) { 16 if (lseek(archive_handle->src_fd, (off_t) amount, SEEK_CUR) == (off_t) -1) {
17#ifdef CONFIG_FEATURE_UNARCHIVE_TAPE 17#ifdef CONFIG_FEATURE_UNARCHIVE_TAPE
18 if (errno == ESPIPE) { 18 if (errno == ESPIPE) {
19 seek_by_char(archive_handle, amount); 19 seek_by_read(archive_handle, amount);
20 } else 20 } else
21#endif 21#endif
22 bb_perror_msg_and_die("Seek failure"); 22 bb_perror_msg_and_die("Seek failure");
diff --git a/archival/libunarchive/seek_by_char.c b/archival/libunarchive/seek_by_read.c
index f4d8c2f2b..03cbb9ecc 100644
--- a/archival/libunarchive/seek_by_char.c
+++ b/archival/libunarchive/seek_by_read.c
@@ -8,14 +8,10 @@
8#include "unarchive.h" 8#include "unarchive.h"
9#include "libbb.h" 9#include "libbb.h"
10 10
11 11/* If we are reading through a pipe(), or from stdin then we cant lseek,
12
13/* If we are reading through a pipe(), or from stdin then we cant lseek,
14 * we must read and discard the data to skip over it. 12 * we must read and discard the data to skip over it.
15 *
16 * TODO: rename to seek_by_read
17 */ 13 */
18void seek_by_char(const archive_handle_t *archive_handle, const unsigned int jump_size) 14void seek_by_read(const archive_handle_t *archive_handle, const unsigned int jump_size)
19{ 15{
20 if (jump_size) { 16 if (jump_size) {
21 bb_copyfd_size(archive_handle->src_fd, -1, jump_size); 17 bb_copyfd_size(archive_handle->src_fd, -1, jump_size);
diff --git a/archival/rpm.c b/archival/rpm.c
index dc37e0edb..448a479a0 100644
--- a/archival/rpm.c
+++ b/archival/rpm.c
@@ -173,7 +173,7 @@ static void extract_cpio_gz(int fd) {
173 173
174 /* Initialise */ 174 /* Initialise */
175 archive_handle = init_handle(); 175 archive_handle = init_handle();
176 archive_handle->seek = seek_by_char; 176 archive_handle->seek = seek_by_read;
177 //archive_handle->action_header = header_list; 177 //archive_handle->action_header = header_list;
178 archive_handle->action_data = data_extract_all; 178 archive_handle->action_data = data_extract_all;
179 archive_handle->flags |= ARCHIVE_PRESERVE_DATE; 179 archive_handle->flags |= ARCHIVE_PRESERVE_DATE;
diff --git a/archival/tar.c b/archival/tar.c
index 3775598cc..b2ae3b2af 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -541,7 +541,7 @@ static llist_t *append_file_list_to_list(llist_t *list)
541static char get_header_tar_Z(archive_handle_t *archive_handle) 541static char get_header_tar_Z(archive_handle_t *archive_handle)
542{ 542{
543 /* Cant lseek over pipe's */ 543 /* Cant lseek over pipe's */
544 archive_handle->seek = seek_by_char; 544 archive_handle->seek = seek_by_read;
545 545
546 /* do the decompression, and cleanup */ 546 /* do the decompression, and cleanup */
547 if (xread_char(archive_handle->src_fd) != 0x1f || 547 if (xread_char(archive_handle->src_fd) != 0x1f ||
@@ -805,7 +805,7 @@ int tar_main(int argc, char **argv)
805 805
806 if ((tar_filename[0] == '-') && (tar_filename[1] == '\0')) { 806 if ((tar_filename[0] == '-') && (tar_filename[1] == '\0')) {
807 tar_handle->src_fd = fileno(tar_stream); 807 tar_handle->src_fd = fileno(tar_stream);
808 tar_handle->seek = seek_by_char; 808 tar_handle->seek = seek_by_read;
809 } else { 809 } else {
810 tar_handle->src_fd = xopen3(tar_filename, flags, 0666); 810 tar_handle->src_fd = xopen3(tar_filename, flags, 0666);
811 } 811 }
diff --git a/archival/unzip.c b/archival/unzip.c
index f63925739..f70baebf9 100644
--- a/archival/unzip.c
+++ b/archival/unzip.c
@@ -51,11 +51,12 @@ typedef union {
51 } formatted ATTRIBUTE_PACKED; 51 } formatted ATTRIBUTE_PACKED;
52} zip_header_t; 52} zip_header_t;
53 53
54/* This one never works with LARGEFILE-sized skips */
54static void unzip_skip(int fd, off_t skip) 55static void unzip_skip(int fd, off_t skip)
55{ 56{
56 if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) { 57 if (lseek(fd, skip, SEEK_CUR) == (off_t)-1) {
57 if ((errno != ESPIPE) || (bb_copyfd_size(fd, -1, skip) != skip)) { 58 if ((errno != ESPIPE) || (bb_copyfd_size(fd, -1, skip) != skip)) {
58 bb_error_msg_and_die("Seek failure"); 59 bb_error_msg_and_die("seek failure");
59 } 60 }
60 } 61 }
61} 62}
@@ -65,7 +66,7 @@ static void unzip_create_leading_dirs(char *fn)
65 /* Create all leading directories */ 66 /* Create all leading directories */
66 char *name = xstrdup(fn); 67 char *name = xstrdup(fn);
67 if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) { 68 if (bb_make_directory(dirname(name), 0777, FILEUTILS_RECUR)) {
68 bb_error_msg_and_die("Exiting"); /* bb_make_directory is noisy */ 69 bb_error_msg_and_die("exiting"); /* bb_make_directory is noisy */
69 } 70 }
70 free(name); 71 free(name);
71} 72}
@@ -76,7 +77,7 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
76 /* Method 0 - stored (not compressed) */ 77 /* Method 0 - stored (not compressed) */
77 int size = zip_header->formatted.ucmpsize; 78 int size = zip_header->formatted.ucmpsize;
78 if (size && (bb_copyfd_size(src_fd, dst_fd, size) != size)) { 79 if (size && (bb_copyfd_size(src_fd, dst_fd, size) != size)) {
79 bb_error_msg_and_die("Cannot complete extraction"); 80 bb_error_msg_and_die("cannot complete extraction");
80 } 81 }
81 82
82 } else { 83 } else {
@@ -86,12 +87,12 @@ static int unzip_extract(zip_header_t *zip_header, int src_fd, int dst_fd)
86 inflate_cleanup(); 87 inflate_cleanup();
87 /* Validate decompression - crc */ 88 /* Validate decompression - crc */
88 if (zip_header->formatted.crc32 != (gunzip_crc ^ 0xffffffffL)) { 89 if (zip_header->formatted.crc32 != (gunzip_crc ^ 0xffffffffL)) {
89 bb_error_msg("Invalid compressed data--crc error"); 90 bb_error_msg("invalid compressed data--%s error", "crc");
90 return 1; 91 return 1;
91 } 92 }
92 /* Validate decompression - size */ 93 /* Validate decompression - size */
93 if (zip_header->formatted.ucmpsize != gunzip_bytes_out) { 94 if (zip_header->formatted.ucmpsize != gunzip_bytes_out) {
94 bb_error_msg("Invalid compressed data--length error"); 95 bb_error_msg("invalid compressed data--%s error", "length");
95 return 1; 96 return 1;
96 } 97 }
97 } 98 }