diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-11 16:23:35 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-11 16:23:35 +0000 |
commit | 4949faf4b2090ca23c2aeb34535fdbe57754913a (patch) | |
tree | b292a499341d3c0314283e2822a93241a1c4e1dd /archival | |
parent | 5b20d02ea98c41bbd8a49cdbb84f425fa9ef446e (diff) | |
download | busybox-w32-4949faf4b2090ca23c2aeb34535fdbe57754913a.tar.gz busybox-w32-4949faf4b2090ca23c2aeb34535fdbe57754913a.tar.bz2 busybox-w32-4949faf4b2090ca23c2aeb34535fdbe57754913a.zip |
copy_file_chunk uses streams now.
Diffstat (limited to 'archival')
-rw-r--r-- | archival/ar.c | 36 | ||||
-rw-r--r-- | archival/dpkg.c | 34 | ||||
-rw-r--r-- | archival/dpkg_deb.c | 2 |
3 files changed, 37 insertions, 35 deletions
diff --git a/archival/ar.c b/archival/ar.c index fbbc7aa64..8ab386821 100644 --- a/archival/ar.c +++ b/archival/ar.c | |||
@@ -36,12 +36,13 @@ extern int ar_main(int argc, char **argv) | |||
36 | const int extract_to_file = 8; /* extract contents of archive */ | 36 | const int extract_to_file = 8; /* extract contents of archive */ |
37 | const int extract_to_stdout = 16; /* extract to stdout */ | 37 | const int extract_to_stdout = 16; /* extract to stdout */ |
38 | 38 | ||
39 | FILE *src_file = NULL, *dst_file = NULL; | ||
39 | int funct = 0, opt=0; | 40 | int funct = 0, opt=0; |
40 | int srcFd=0, dstFd=0; | ||
41 | 41 | ||
42 | ar_headers_t head, *extract_list=NULL; | 42 | ar_headers_t *head, *extract_list=NULL; |
43 | 43 | ||
44 | extract_list = (ar_headers_t *) xmalloc(sizeof(ar_headers_t)); | 44 | extract_list = (ar_headers_t *) xcalloc(1, sizeof(ar_headers_t)); |
45 | head = (ar_headers_t *) xcalloc(1, sizeof(ar_headers_t)); | ||
45 | 46 | ||
46 | while ((opt = getopt(argc, argv, "ovtpx")) != -1) { | 47 | while ((opt = getopt(argc, argv, "ovtpx")) != -1) { |
47 | switch (opt) { | 48 | switch (opt) { |
@@ -66,21 +67,22 @@ extern int ar_main(int argc, char **argv) | |||
66 | } | 67 | } |
67 | 68 | ||
68 | /* check the src filename was specified */ | 69 | /* check the src filename was specified */ |
69 | if (optind == argc) | 70 | if (optind == argc) { |
70 | show_usage(); | 71 | show_usage(); |
71 | 72 | } | |
72 | if ( (srcFd = open(argv[optind], O_RDONLY)) < 0) | 73 | |
74 | if ( (src_file = wfopen(argv[optind], "r")) < 0) { | ||
73 | error_msg_and_die("Cannot read %s", argv[optind]); | 75 | error_msg_and_die("Cannot read %s", argv[optind]); |
76 | } | ||
74 | 77 | ||
75 | optind++; | 78 | optind++; |
76 | head = get_ar_headers(srcFd); | 79 | head = get_ar_headers(src_file); |
77 | |||
78 | /* find files to extract or display */ | 80 | /* find files to extract or display */ |
79 | /* search through argv and build extract list */ | 81 | /* search through argv and build extract list */ |
80 | for (;optind<argc; optind++) { | 82 | for (;optind < argc; optind++) { |
81 | ar_headers_t *ar_entry; | 83 | ar_headers_t *ar_entry; |
82 | ar_entry = (ar_headers_t *) xmalloc(sizeof(ar_headers_t)); | 84 | ar_entry = (ar_headers_t *) xcalloc(1, sizeof(ar_headers_t)); |
83 | ar_entry = &head; | 85 | ar_entry = head; |
84 | while (ar_entry->next != NULL) { | 86 | while (ar_entry->next != NULL) { |
85 | if (strcmp(argv[optind], ar_entry->name) == 0) { | 87 | if (strcmp(argv[optind], ar_entry->name) == 0) { |
86 | ar_headers_t *tmp; | 88 | ar_headers_t *tmp; |
@@ -96,20 +98,20 @@ extern int ar_main(int argc, char **argv) | |||
96 | 98 | ||
97 | /* if individual files not found extract all files */ | 99 | /* if individual files not found extract all files */ |
98 | if (extract_list->next==NULL) { | 100 | if (extract_list->next==NULL) { |
99 | extract_list = &head; | 101 | extract_list = head; |
100 | } | 102 | } |
101 | 103 | ||
102 | /* find files to extract or display */ | 104 | /* find files to extract or display */ |
103 | while (extract_list->next != NULL) { | 105 | while (extract_list->next != NULL) { |
104 | if (funct & extract_to_file) { | 106 | if (funct & extract_to_file) { |
105 | dstFd = open(extract_list->name, O_WRONLY | O_CREAT, extract_list->mode); | 107 | dst_file = wfopen(extract_list->name, "w"); |
106 | } | 108 | } |
107 | else if (funct & extract_to_stdout) { | 109 | else if (funct & extract_to_stdout) { |
108 | dstFd = fileno(stdout); | 110 | dst_file = stdout; |
109 | } | 111 | } |
110 | if ((funct & extract_to_file) || (funct & extract_to_stdout)) { | 112 | if ((funct & extract_to_file) || (funct & extract_to_stdout)) { |
111 | lseek(srcFd, extract_list->offset, SEEK_SET); | 113 | fseek(src_file, extract_list->offset, SEEK_SET); |
112 | copy_file_chunk(srcFd, dstFd, (off_t) extract_list->size); | 114 | copy_file_chunk(src_file, dst_file, (off_t) extract_list->size); |
113 | } | 115 | } |
114 | if (funct & verbose) { | 116 | if (funct & verbose) { |
115 | printf("%s %d/%d %8d %s ", mode_string(extract_list->mode), | 117 | printf("%s %d/%d %8d %s ", mode_string(extract_list->mode), |
diff --git a/archival/dpkg.c b/archival/dpkg.c index 55d97adda..d0728d995 100644 --- a/archival/dpkg.c +++ b/archival/dpkg.c | |||
@@ -565,8 +565,8 @@ static int dpkg_dounpack(package_t *pkg) | |||
565 | int r = 0, i; | 565 | int r = 0, i; |
566 | int status = TRUE; | 566 | int status = TRUE; |
567 | char *cwd = xgetcwd(0); | 567 | char *cwd = xgetcwd(0); |
568 | char *src_file = NULL; | 568 | char *src_filename = NULL; |
569 | char *dst_file = NULL; | 569 | char *dst_filename = NULL; |
570 | // char *lst_file = NULL; | 570 | // char *lst_file = NULL; |
571 | char *adminscripts[] = { "prerm", "postrm", "preinst", "postinst", | 571 | char *adminscripts[] = { "prerm", "postrm", "preinst", "postinst", |
572 | "conffiles", "md5sums", "shlibs", "templates" }; | 572 | "conffiles", "md5sums", "shlibs", "templates" }; |
@@ -576,37 +576,37 @@ static int dpkg_dounpack(package_t *pkg) | |||
576 | if(cwd==NULL) | 576 | if(cwd==NULL) |
577 | exit(EXIT_FAILURE); | 577 | exit(EXIT_FAILURE); |
578 | chdir("/"); | 578 | chdir("/"); |
579 | deb_extract(dpkg_deb_extract, "/", pkg->file); | 579 | deb_extract(pkg->file, dpkg_deb_extract, "/"); |
580 | 580 | ||
581 | /* Installs the package scripts into the info directory */ | 581 | /* Installs the package scripts into the info directory */ |
582 | for (i = 0; i < sizeof(adminscripts) / sizeof(adminscripts[0]); i++) { | 582 | for (i = 0; i < sizeof(adminscripts) / sizeof(adminscripts[0]); i++) { |
583 | struct stat src_stat_buf; | 583 | struct stat src_stat_buf; |
584 | int src_fd = 0, dst_fd = 0; | 584 | FILE *src_file = NULL, *dst_file = NULL; |
585 | 585 | ||
586 | /* The full path of the current location of the admin file */ | 586 | /* The full path of the current location of the admin file */ |
587 | src_file = xrealloc(src_file, strlen(dpkgcidir) + strlen(pkg->package) + strlen(adminscripts[i]) + 1); | 587 | src_filename = xrealloc(src_filename, strlen(dpkgcidir) + strlen(pkg->package) + strlen(adminscripts[i]) + 1); |
588 | sprintf(src_file, "%s%s/%s", dpkgcidir, pkg->package, adminscripts[i]); | 588 | sprintf(src_filename, "%s%s/%s", dpkgcidir, pkg->package, adminscripts[i]); |
589 | 589 | ||
590 | /* the full path of where we want the file to be copied to */ | 590 | /* the full path of where we want the file to be copied to */ |
591 | dst_file = xrealloc(dst_file, strlen(infodir) + strlen(pkg->package) + strlen(adminscripts[i]) + 1); | 591 | dst_filename = xrealloc(dst_filename, strlen(infodir) + strlen(pkg->package) + strlen(adminscripts[i]) + 1); |
592 | sprintf(dst_file, "%s%s.%s", infodir, pkg->package, adminscripts[i]); | 592 | sprintf(dst_filename, "%s%s.%s", infodir, pkg->package, adminscripts[i]); |
593 | 593 | ||
594 | /* | 594 | /* |
595 | * copy admin file to permanent home | 595 | * copy admin file to permanent home |
596 | * NOTE: Maybe merge this behaviour into libb/copy_file.c | 596 | * NOTE: Maybe merge this behaviour into libb/copy_file.c |
597 | */ | 597 | */ |
598 | if (lstat(src_file, &src_stat_buf) == 0) { | 598 | if (lstat(src_filename, &src_stat_buf) == 0) { |
599 | if ((src_fd = open(src_file, O_RDONLY)) != -1) { | 599 | if ((src_file = wfopen(src_filename, "r")) != NULL) { |
600 | if ((dst_fd = open(dst_file, O_WRONLY | O_CREAT, 0644)) == -1) { | 600 | if ((dst_file = wfopen(dst_filename, "w")) == NULL) { |
601 | status = FALSE; | 601 | status = FALSE; |
602 | perror_msg("Opening %s", dst_file); | 602 | perror_msg("Opening %s", dst_filename); |
603 | } | 603 | } |
604 | copy_file_chunk(src_fd, dst_fd, src_stat_buf.st_size); | 604 | copy_file_chunk(src_file, dst_file, src_stat_buf.st_size); |
605 | close(src_fd); | 605 | fclose(src_file); |
606 | close(dst_fd); | 606 | fclose(dst_file); |
607 | } else { | 607 | } else { |
608 | status = FALSE; | 608 | status = FALSE; |
609 | error_msg("couldnt open [%s]\n", src_file); | 609 | error_msg("couldnt open [%s]\n", src_filename); |
610 | } | 610 | } |
611 | } | 611 | } |
612 | } | 612 | } |
@@ -671,7 +671,7 @@ static int dpkg_unpackcontrol(package_t *pkg) | |||
671 | strcat(tmp_name, pkg->package); | 671 | strcat(tmp_name, pkg->package); |
672 | 672 | ||
673 | /* extract control.tar.gz to the full extraction path */ | 673 | /* extract control.tar.gz to the full extraction path */ |
674 | deb_extract(dpkg_deb_control, tmp_name, pkg->file); | 674 | deb_extract(pkg->file, dpkg_deb_control, tmp_name); |
675 | 675 | ||
676 | /* parse the extracted control file */ | 676 | /* parse the extracted control file */ |
677 | strcat(tmp_name, "/control"); | 677 | strcat(tmp_name, "/control"); |
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c index 450b04b8e..3cdd4ffae 100644 --- a/archival/dpkg_deb.c +++ b/archival/dpkg_deb.c | |||
@@ -68,7 +68,7 @@ extern int dpkg_deb_main(int argc, char **argv) | |||
68 | strcpy(target_dir, argv[optind + 1]); | 68 | strcpy(target_dir, argv[optind + 1]); |
69 | } | 69 | } |
70 | } | 70 | } |
71 | deb_extract(optflag, target_dir, argv[optind]); | 71 | deb_extract(argv[optind], optflag, target_dir); |
72 | /* else if (optflag & dpkg_deb_info) { | 72 | /* else if (optflag & dpkg_deb_info) { |
73 | extract_flag = TRUE; | 73 | extract_flag = TRUE; |
74 | extract_to_stdout = TRUE; | 74 | extract_to_stdout = TRUE; |