diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-06 10:53:17 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-06 10:53:17 +0100 |
commit | aa4977d8e549d9fff2b2946f03d304e435eb20f1 (patch) | |
tree | bc7c7fe4ab64263a9f8356762cb8f7e77165de73 /archival/libunarchive | |
parent | 86350f8d5f5d5a1006cffe0bedccd625f012702f (diff) | |
download | busybox-w32-aa4977d8e549d9fff2b2946f03d304e435eb20f1.tar.gz busybox-w32-aa4977d8e549d9fff2b2946f03d304e435eb20f1.tar.bz2 busybox-w32-aa4977d8e549d9fff2b2946f03d304e435eb20f1.zip |
libunarchive: clean up dirty hacks. code shrank as a result
function old new delta
cpio_main 526 539 +13
init_handle 57 58 +1
init_archive_deb_ar 34 35 +1
get_header_ar 408 409 +1
dpkg_main 3900 3901 +1
unpack_package 516 515 -1
rpm_main 1673 1672 -1
tar_main 774 767 -7
get_header_cpio 990 972 -18
data_extract_all 750 727 -23
get_header_tar 1631 1576 -55
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 5/6 up/down: 17/-105) Total: -88 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'archival/libunarchive')
-rw-r--r-- | archival/libunarchive/data_extract_all.c | 8 | ||||
-rw-r--r-- | archival/libunarchive/filter_accept_list_reassign.c | 6 | ||||
-rw-r--r-- | archival/libunarchive/get_header_ar.c | 4 | ||||
-rw-r--r-- | archival/libunarchive/get_header_cpio.c | 37 | ||||
-rw-r--r-- | archival/libunarchive/get_header_tar.c | 29 | ||||
-rw-r--r-- | archival/libunarchive/header_verbose_list.c | 4 |
6 files changed, 36 insertions, 52 deletions
diff --git a/archival/libunarchive/data_extract_all.c b/archival/libunarchive/data_extract_all.c index 874d37d94..58b05335b 100644 --- a/archival/libunarchive/data_extract_all.c +++ b/archival/libunarchive/data_extract_all.c | |||
@@ -127,13 +127,13 @@ void FAST_FUNC data_extract_all(archive_handle_t *archive_handle) | |||
127 | uid_t uid = file_header->uid; | 127 | uid_t uid = file_header->uid; |
128 | gid_t gid = file_header->gid; | 128 | gid_t gid = file_header->gid; |
129 | 129 | ||
130 | if (file_header->uname) { | 130 | if (file_header->tar__uname) { |
131 | //TODO: cache last name/id pair? | 131 | //TODO: cache last name/id pair? |
132 | struct passwd *pwd = getpwnam(file_header->uname); | 132 | struct passwd *pwd = getpwnam(file_header->tar__uname); |
133 | if (pwd) uid = pwd->pw_uid; | 133 | if (pwd) uid = pwd->pw_uid; |
134 | } | 134 | } |
135 | if (file_header->gname) { | 135 | if (file_header->tar__gname) { |
136 | struct group *grp = getgrnam(file_header->gname); | 136 | struct group *grp = getgrnam(file_header->tar__gname); |
137 | if (grp) gid = grp->gr_gid; | 137 | if (grp) gid = grp->gr_gid; |
138 | } | 138 | } |
139 | /* GNU tar 1.15.1 uses chown, not lchown */ | 139 | /* GNU tar 1.15.1 uses chown, not lchown */ |
diff --git a/archival/libunarchive/filter_accept_list_reassign.c b/archival/libunarchive/filter_accept_list_reassign.c index f1de4e803..060a2c72b 100644 --- a/archival/libunarchive/filter_accept_list_reassign.c +++ b/archival/libunarchive/filter_accept_list_reassign.c | |||
@@ -31,19 +31,19 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t *archive_handle) | |||
31 | if (ENABLE_FEATURE_SEAMLESS_GZ | 31 | if (ENABLE_FEATURE_SEAMLESS_GZ |
32 | && strcmp(name_ptr, "gz") == 0 | 32 | && strcmp(name_ptr, "gz") == 0 |
33 | ) { | 33 | ) { |
34 | archive_handle->action_data_subarchive = get_header_tar_gz; | 34 | archive_handle->dpkg__action_data_subarchive = get_header_tar_gz; |
35 | return EXIT_SUCCESS; | 35 | return EXIT_SUCCESS; |
36 | } | 36 | } |
37 | if (ENABLE_FEATURE_SEAMLESS_BZ2 | 37 | if (ENABLE_FEATURE_SEAMLESS_BZ2 |
38 | && strcmp(name_ptr, "bz2") == 0 | 38 | && strcmp(name_ptr, "bz2") == 0 |
39 | ) { | 39 | ) { |
40 | archive_handle->action_data_subarchive = get_header_tar_bz2; | 40 | archive_handle->dpkg__action_data_subarchive = get_header_tar_bz2; |
41 | return EXIT_SUCCESS; | 41 | return EXIT_SUCCESS; |
42 | } | 42 | } |
43 | if (ENABLE_FEATURE_SEAMLESS_LZMA | 43 | if (ENABLE_FEATURE_SEAMLESS_LZMA |
44 | && strcmp(name_ptr, "lzma") == 0 | 44 | && strcmp(name_ptr, "lzma") == 0 |
45 | ) { | 45 | ) { |
46 | archive_handle->action_data_subarchive = get_header_tar_lzma; | 46 | archive_handle->dpkg__action_data_subarchive = get_header_tar_lzma; |
47 | return EXIT_SUCCESS; | 47 | return EXIT_SUCCESS; |
48 | } | 48 | } |
49 | } | 49 | } |
diff --git a/archival/libunarchive/get_header_ar.c b/archival/libunarchive/get_header_ar.c index e6d712d8d..2f38279cc 100644 --- a/archival/libunarchive/get_header_ar.c +++ b/archival/libunarchive/get_header_ar.c | |||
@@ -122,8 +122,8 @@ char FAST_FUNC get_header_ar(archive_handle_t *archive_handle) | |||
122 | if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { | 122 | if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) { |
123 | archive_handle->action_header(typed); | 123 | archive_handle->action_header(typed); |
124 | #if ENABLE_DPKG || ENABLE_DPKG_DEB | 124 | #if ENABLE_DPKG || ENABLE_DPKG_DEB |
125 | if (archive_handle->sub_archive) { | 125 | if (archive_handle->dpkg__sub_archive) { |
126 | while (archive_handle->action_data_subarchive(archive_handle->sub_archive) == EXIT_SUCCESS) | 126 | while (archive_handle->dpkg__action_data_subarchive(archive_handle->dpkg__sub_archive) == EXIT_SUCCESS) |
127 | continue; | 127 | continue; |
128 | } else | 128 | } else |
129 | #endif | 129 | #endif |
diff --git a/archival/libunarchive/get_header_cpio.c b/archival/libunarchive/get_header_cpio.c index 52854dff9..ddc49f70e 100644 --- a/archival/libunarchive/get_header_cpio.c +++ b/archival/libunarchive/get_header_cpio.c | |||
@@ -25,15 +25,6 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) | |||
25 | int major, minor, nlink, mode, inode; | 25 | int major, minor, nlink, mode, inode; |
26 | unsigned size, uid, gid, mtime; | 26 | unsigned size, uid, gid, mtime; |
27 | 27 | ||
28 | #define hardlinks_to_create (*(hardlinks_t **)(&archive_handle->ah_priv[0])) | ||
29 | #define created_hardlinks (*(hardlinks_t **)(&archive_handle->ah_priv[1])) | ||
30 | #define block_count (archive_handle->ah_priv[2]) | ||
31 | // if (!archive_handle->ah_priv_inited) { | ||
32 | // archive_handle->ah_priv_inited = 1; | ||
33 | // hardlinks_to_create = NULL; | ||
34 | // created_hardlinks = NULL; | ||
35 | // } | ||
36 | |||
37 | /* There can be padding before archive header */ | 28 | /* There can be padding before archive header */ |
38 | data_align(archive_handle, 4); | 29 | data_align(archive_handle, 4); |
39 | 30 | ||
@@ -86,7 +77,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) | |||
86 | 77 | ||
87 | if (strcmp(file_header->name, "TRAILER!!!") == 0) { | 78 | if (strcmp(file_header->name, "TRAILER!!!") == 0) { |
88 | /* Always round up. ">> 9" divides by 512 */ | 79 | /* Always round up. ">> 9" divides by 512 */ |
89 | block_count = (void*)(ptrdiff_t) ((archive_handle->offset + 511) >> 9); | 80 | archive_handle->cpio__blocks = (uoff_t)(archive_handle->offset + 511) >> 9; |
90 | goto create_hardlinks; | 81 | goto create_hardlinks; |
91 | } | 82 | } |
92 | 83 | ||
@@ -112,13 +103,13 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) | |||
112 | strcpy(new->name, file_header->name); | 103 | strcpy(new->name, file_header->name); |
113 | /* Put file on a linked list for later */ | 104 | /* Put file on a linked list for later */ |
114 | if (size == 0) { | 105 | if (size == 0) { |
115 | new->next = hardlinks_to_create; | 106 | new->next = archive_handle->cpio__hardlinks_to_create; |
116 | hardlinks_to_create = new; | 107 | archive_handle->cpio__hardlinks_to_create = new; |
117 | return EXIT_SUCCESS; /* Skip this one */ | 108 | return EXIT_SUCCESS; /* Skip this one */ |
118 | /* TODO: this breaks cpio -t (it does not show hardlinks) */ | 109 | /* TODO: this breaks cpio -t (it does not show hardlinks) */ |
119 | } | 110 | } |
120 | new->next = created_hardlinks; | 111 | new->next = archive_handle->cpio__created_hardlinks; |
121 | created_hardlinks = new; | 112 | archive_handle->cpio__created_hardlinks = new; |
122 | } | 113 | } |
123 | file_header->device = makedev(major, minor); | 114 | file_header->device = makedev(major, minor); |
124 | 115 | ||
@@ -142,11 +133,11 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) | |||
142 | free(file_header->link_target); | 133 | free(file_header->link_target); |
143 | free(file_header->name); | 134 | free(file_header->name); |
144 | 135 | ||
145 | while (hardlinks_to_create) { | 136 | while (archive_handle->cpio__hardlinks_to_create) { |
146 | hardlinks_t *cur; | 137 | hardlinks_t *cur; |
147 | hardlinks_t *make_me = hardlinks_to_create; | 138 | hardlinks_t *make_me = archive_handle->cpio__hardlinks_to_create; |
148 | 139 | ||
149 | hardlinks_to_create = make_me->next; | 140 | archive_handle->cpio__hardlinks_to_create = make_me->next; |
150 | 141 | ||
151 | memset(file_header, 0, sizeof(*file_header)); | 142 | memset(file_header, 0, sizeof(*file_header)); |
152 | file_header->mtime = make_me->mtime; | 143 | file_header->mtime = make_me->mtime; |
@@ -158,7 +149,7 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) | |||
158 | /*file_header->link_target = NULL;*/ | 149 | /*file_header->link_target = NULL;*/ |
159 | 150 | ||
160 | /* Try to find a file we are hardlinked to */ | 151 | /* Try to find a file we are hardlinked to */ |
161 | cur = created_hardlinks; | 152 | cur = archive_handle->cpio__created_hardlinks; |
162 | while (cur) { | 153 | while (cur) { |
163 | /* TODO: must match maj/min too! */ | 154 | /* TODO: must match maj/min too! */ |
164 | if (cur->inode == make_me->inode) { | 155 | if (cur->inode == make_me->inode) { |
@@ -176,14 +167,14 @@ char FAST_FUNC get_header_cpio(archive_handle_t *archive_handle) | |||
176 | if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) | 167 | if (archive_handle->filter(archive_handle) == EXIT_SUCCESS) |
177 | archive_handle->action_data(archive_handle); | 168 | archive_handle->action_data(archive_handle); |
178 | /* Move to the list of created hardlinked files */ | 169 | /* Move to the list of created hardlinked files */ |
179 | make_me->next = created_hardlinks; | 170 | make_me->next = archive_handle->cpio__created_hardlinks; |
180 | created_hardlinks = make_me; | 171 | archive_handle->cpio__created_hardlinks = make_me; |
181 | next_link: ; | 172 | next_link: ; |
182 | } | 173 | } |
183 | 174 | ||
184 | while (created_hardlinks) { | 175 | while (archive_handle->cpio__created_hardlinks) { |
185 | hardlinks_t *p = created_hardlinks; | 176 | hardlinks_t *p = archive_handle->cpio__created_hardlinks; |
186 | created_hardlinks = p->next; | 177 | archive_handle->cpio__created_hardlinks = p->next; |
187 | free(p); | 178 | free(p); |
188 | } | 179 | } |
189 | 180 | ||
diff --git a/archival/libunarchive/get_header_tar.c b/archival/libunarchive/get_header_tar.c index 1f799277b..982404d14 100644 --- a/archival/libunarchive/get_header_tar.c +++ b/archival/libunarchive/get_header_tar.c | |||
@@ -135,20 +135,13 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | |||
135 | int parse_names; | 135 | int parse_names; |
136 | 136 | ||
137 | /* Our "private data" */ | 137 | /* Our "private data" */ |
138 | #define p_end (*(smallint *)(&archive_handle->ah_priv[0])) | ||
139 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS | 138 | #if ENABLE_FEATURE_TAR_GNU_EXTENSIONS |
140 | #define p_longname (*(char* *)(&archive_handle->ah_priv[1])) | 139 | # define p_longname (archive_handle->tar__longname) |
141 | #define p_linkname (*(char* *)(&archive_handle->ah_priv[2])) | 140 | # define p_linkname (archive_handle->tar__linkname) |
142 | #else | 141 | #else |
143 | #define p_longname 0 | 142 | # define p_longname 0 |
144 | #define p_linkname 0 | 143 | # define p_linkname 0 |
145 | #endif | 144 | #endif |
146 | // if (!archive_handle->ah_priv_inited) { | ||
147 | // archive_handle->ah_priv_inited = 1; | ||
148 | // p_end = 0; | ||
149 | // IF_FEATURE_TAR_GNU_EXTENSIONS(p_longname = NULL;) | ||
150 | // IF_FEATURE_TAR_GNU_EXTENSIONS(p_linkname = NULL;) | ||
151 | // } | ||
152 | 145 | ||
153 | if (sizeof(tar) != 512) | 146 | if (sizeof(tar) != 512) |
154 | BUG_tar_header_size(); | 147 | BUG_tar_header_size(); |
@@ -190,7 +183,7 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | |||
190 | 183 | ||
191 | /* If there is no filename its an empty header */ | 184 | /* If there is no filename its an empty header */ |
192 | if (tar.name[0] == 0 && tar.prefix[0] == 0) { | 185 | if (tar.name[0] == 0 && tar.prefix[0] == 0) { |
193 | if (p_end) { | 186 | if (archive_handle->tar__end) { |
194 | /* Second consecutive empty header - end of archive. | 187 | /* Second consecutive empty header - end of archive. |
195 | * Read until the end to empty the pipe from gz or bz2 | 188 | * Read until the end to empty the pipe from gz or bz2 |
196 | */ | 189 | */ |
@@ -198,10 +191,10 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | |||
198 | continue; | 191 | continue; |
199 | return EXIT_FAILURE; | 192 | return EXIT_FAILURE; |
200 | } | 193 | } |
201 | p_end = 1; | 194 | archive_handle->tar__end = 1; |
202 | return EXIT_SUCCESS; | 195 | return EXIT_SUCCESS; |
203 | } | 196 | } |
204 | p_end = 0; | 197 | archive_handle->tar__end = 0; |
205 | 198 | ||
206 | /* Check header has valid magic, "ustar" is for the proper tar, | 199 | /* Check header has valid magic, "ustar" is for the proper tar, |
207 | * five NULs are for the old tar format */ | 200 | * five NULs are for the old tar format */ |
@@ -301,8 +294,8 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | |||
301 | /* Will link_target be free()ed? */ | 294 | /* Will link_target be free()ed? */ |
302 | } | 295 | } |
303 | #if ENABLE_FEATURE_TAR_UNAME_GNAME | 296 | #if ENABLE_FEATURE_TAR_UNAME_GNAME |
304 | file_header->uname = tar.uname[0] ? xstrndup(tar.uname, sizeof(tar.uname)) : NULL; | 297 | file_header->tar__uname = tar.uname[0] ? xstrndup(tar.uname, sizeof(tar.uname)) : NULL; |
305 | file_header->gname = tar.gname[0] ? xstrndup(tar.gname, sizeof(tar.gname)) : NULL; | 298 | file_header->tar__gname = tar.gname[0] ? xstrndup(tar.gname, sizeof(tar.gname)) : NULL; |
306 | #endif | 299 | #endif |
307 | /* mtime: rudimentally handle GNU tar's "base256 encoding" | 300 | /* mtime: rudimentally handle GNU tar's "base256 encoding" |
308 | * People report tarballs with NEGATIVE unix times encoded that way */ | 301 | * People report tarballs with NEGATIVE unix times encoded that way */ |
@@ -449,8 +442,8 @@ char FAST_FUNC get_header_tar(archive_handle_t *archive_handle) | |||
449 | free(file_header->link_target); | 442 | free(file_header->link_target); |
450 | /* Do not free(file_header->name)! (why?) */ | 443 | /* Do not free(file_header->name)! (why?) */ |
451 | #if ENABLE_FEATURE_TAR_UNAME_GNAME | 444 | #if ENABLE_FEATURE_TAR_UNAME_GNAME |
452 | free(file_header->uname); | 445 | free(file_header->tar__uname); |
453 | free(file_header->gname); | 446 | free(file_header->tar__gname); |
454 | #endif | 447 | #endif |
455 | return EXIT_SUCCESS; | 448 | return EXIT_SUCCESS; |
456 | } | 449 | } |
diff --git a/archival/libunarchive/header_verbose_list.c b/archival/libunarchive/header_verbose_list.c index 102cd9e11..da21a15af 100644 --- a/archival/libunarchive/header_verbose_list.c +++ b/archival/libunarchive/header_verbose_list.c | |||
@@ -16,12 +16,12 @@ void FAST_FUNC header_verbose_list(const file_header_t *file_header) | |||
16 | char *user; | 16 | char *user; |
17 | char *group; | 17 | char *group; |
18 | 18 | ||
19 | user = file_header->uname; | 19 | user = file_header->tar__uname; |
20 | if (user == NULL) { | 20 | if (user == NULL) { |
21 | sprintf(uid, "%u", (unsigned)file_header->uid); | 21 | sprintf(uid, "%u", (unsigned)file_header->uid); |
22 | user = uid; | 22 | user = uid; |
23 | } | 23 | } |
24 | group = file_header->gname; | 24 | group = file_header->tar__gname; |
25 | if (group == NULL) { | 25 | if (group == NULL) { |
26 | /*sprintf(gid, "%u", (unsigned)file_header->gid);*/ | 26 | /*sprintf(gid, "%u", (unsigned)file_header->gid);*/ |
27 | group = utoa(file_header->gid); | 27 | group = utoa(file_header->gid); |