diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-11 03:06:00 +0400 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-07-11 03:06:00 +0400 |
commit | 0381d422d9b40c0cf887d299224c7759875aefd8 (patch) | |
tree | 764583282951c07bb6b611bef2858c5375647094 /archival/dpkg_deb.c | |
parent | b6052724ffc9d45894147b70e7aff226938bd2d3 (diff) |
dpkg_deb: slight code shrink
ar: reuse existing ar unpacking code
get_header_tar: handle autodetection for tiny .tar.gz files too
unarchive.h: do not include CONFIGed out things
function old new delta
get_header_tar 1521 1534 +13
dpkg_deb_main 400 380 -20
ar_main 260 196 -64
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/2 up/down: 13/-84) Total: -71 bytes
Diffstat (limited to 'archival/dpkg_deb.c')
-rw-r--r-- | archival/dpkg_deb.c | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index cbacc91f8..9e6340fd3 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c @@ -20,8 +20,8 @@ int dpkg_deb_main(int argc, char **argv) archive_handle_t *tar_archive; llist_t *control_tar_llist = NULL; unsigned opt; - const char *extract_dir = NULL; - short argcount = 1; + const char *extract_dir; + int need_args; /* Setup the tar archive handle */ tar_archive = init_handle(); @@ -43,17 +43,21 @@ int dpkg_deb_main(int argc, char **argv) opt_complementary = "c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX"; opt = getopt32(argv, "cefXx"); + argv += optind; + argc -= optind; if (opt & DPKG_DEB_OPT_CONTENTS) { tar_archive->action_header = header_verbose_list; } + extract_dir = NULL; + need_args = 1; if (opt & DPKG_DEB_OPT_CONTROL) { ar_archive->accept = control_tar_llist; tar_archive->action_data = data_extract_all; - if (optind + 1 == argc) { + if (1 == argc) { extract_dir = "./DEBIAN"; } else { - argcount++; + need_args++; } } if (opt & DPKG_DEB_OPT_FIELD) { @@ -70,28 +74,31 @@ int dpkg_deb_main(int argc, char **argv) } if (opt & (DPKG_DEB_OPT_EXTRACT_VERBOSE | DPKG_DEB_OPT_EXTRACT)) { tar_archive->action_data = data_extract_all; - argcount = 2; + need_args = 2; } - if ((optind + argcount) != argc) { + if (need_args != argc) { bb_show_usage(); } - tar_archive->src_fd = ar_archive->src_fd = xopen(argv[optind++], O_RDONLY); + tar_archive->src_fd = ar_archive->src_fd = xopen(argv[0], O_RDONLY); - /* Workout where to extract the files */ + /* Work out where to extract the files */ /* 2nd argument is a dir name */ - if (argv[optind]) { - extract_dir = argv[optind]; + if (argv[1]) { + extract_dir = argv[1]; } if (extract_dir) { mkdir(extract_dir, 0777); /* bb_make_directory(extract_dir, 0777, 0) */ xchdir(extract_dir); } + + /* Do it */ unpack_ar_archive(ar_archive); /* Cleanup */ - close(ar_archive->src_fd); + if (ENABLE_FEATURE_CLEAN_UP) + close(ar_archive->src_fd); return EXIT_SUCCESS; } |