aboutsummaryrefslogtreecommitdiff
path: root/archival/libunarchive
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/libunarchive
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/libunarchive')
-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
8 files changed, 40 insertions, 46 deletions
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);