summaryrefslogtreecommitdiff
path: root/archival
diff options
context:
space:
mode:
Diffstat (limited to 'archival')
-rw-r--r--archival/ar.c36
-rw-r--r--archival/dpkg.c34
-rw-r--r--archival/dpkg_deb.c2
3 files changed, 37 insertions, 35 deletions
diff --git a/archival/ar.c b/archival/ar.c
index fbbc7aa..8ab3868 100644
--- a/archival/ar.c
+++ b/archival/ar.c
@@ -36,12 +36,13 @@ extern int ar_main(int argc, char **argv)
const int extract_to_file = 8; /* extract contents of archive */
const int extract_to_stdout = 16; /* extract to stdout */
+ FILE *src_file = NULL, *dst_file = NULL;
int funct = 0, opt=0;
- int srcFd=0, dstFd=0;
- ar_headers_t head, *extract_list=NULL;
+ ar_headers_t *head, *extract_list=NULL;
- extract_list = (ar_headers_t *) xmalloc(sizeof(ar_headers_t));
+ extract_list = (ar_headers_t *) xcalloc(1, sizeof(ar_headers_t));
+ head = (ar_headers_t *) xcalloc(1, sizeof(ar_headers_t));
while ((opt = getopt(argc, argv, "ovtpx")) != -1) {
switch (opt) {
@@ -66,21 +67,22 @@ extern int ar_main(int argc, char **argv)
}
/* check the src filename was specified */
- if (optind == argc)
+ if (optind == argc) {
show_usage();
-
- if ( (srcFd = open(argv[optind], O_RDONLY)) < 0)
+ }
+
+ if ( (src_file = wfopen(argv[optind], "r")) < 0) {
error_msg_and_die("Cannot read %s", argv[optind]);
+ }
optind++;
- head = get_ar_headers(srcFd);
-
+ head = get_ar_headers(src_file);
/* find files to extract or display */
/* search through argv and build extract list */
- for (;optind<argc; optind++) {
+ for (;optind < argc; optind++) {
ar_headers_t *ar_entry;
- ar_entry = (ar_headers_t *) xmalloc(sizeof(ar_headers_t));
- ar_entry = &head;
+ ar_entry = (ar_headers_t *) xcalloc(1, sizeof(ar_headers_t));
+ ar_entry = head;
while (ar_entry->next != NULL) {
if (strcmp(argv[optind], ar_entry->name) == 0) {
ar_headers_t *tmp;
@@ -96,20 +98,20 @@ extern int ar_main(int argc, char **argv)
/* if individual files not found extract all files */
if (extract_list->next==NULL) {
- extract_list = &head;
+ extract_list = head;
}
-
+
/* find files to extract or display */
while (extract_list->next != NULL) {
if (funct & extract_to_file) {
- dstFd = open(extract_list->name, O_WRONLY | O_CREAT, extract_list->mode);
+ dst_file = wfopen(extract_list->name, "w");
}
else if (funct & extract_to_stdout) {
- dstFd = fileno(stdout);
+ dst_file = stdout;
}
if ((funct & extract_to_file) || (funct & extract_to_stdout)) {
- lseek(srcFd, extract_list->offset, SEEK_SET);
- copy_file_chunk(srcFd, dstFd, (off_t) extract_list->size);
+ fseek(src_file, extract_list->offset, SEEK_SET);
+ copy_file_chunk(src_file, dst_file, (off_t) extract_list->size);
}
if (funct & verbose) {
printf("%s %d/%d %8d %s ", mode_string(extract_list->mode),
diff --git a/archival/dpkg.c b/archival/dpkg.c
index 55d97ad..d0728d9 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -565,8 +565,8 @@ static int dpkg_dounpack(package_t *pkg)
int r = 0, i;
int status = TRUE;
char *cwd = xgetcwd(0);
- char *src_file = NULL;
- char *dst_file = NULL;
+ char *src_filename = NULL;
+ char *dst_filename = NULL;
// char *lst_file = NULL;
char *adminscripts[] = { "prerm", "postrm", "preinst", "postinst",
"conffiles", "md5sums", "shlibs", "templates" };
@@ -576,37 +576,37 @@ static int dpkg_dounpack(package_t *pkg)
if(cwd==NULL)
exit(EXIT_FAILURE);
chdir("/");
- deb_extract(dpkg_deb_extract, "/", pkg->file);
+ deb_extract(pkg->file, dpkg_deb_extract, "/");
/* Installs the package scripts into the info directory */
for (i = 0; i < sizeof(adminscripts) / sizeof(adminscripts[0]); i++) {
struct stat src_stat_buf;
- int src_fd = 0, dst_fd = 0;
+ FILE *src_file = NULL, *dst_file = NULL;
/* The full path of the current location of the admin file */
- src_file = xrealloc(src_file, strlen(dpkgcidir) + strlen(pkg->package) + strlen(adminscripts[i]) + 1);
- sprintf(src_file, "%s%s/%s", dpkgcidir, pkg->package, adminscripts[i]);
+ src_filename = xrealloc(src_filename, strlen(dpkgcidir) + strlen(pkg->package) + strlen(adminscripts[i]) + 1);
+ sprintf(src_filename, "%s%s/%s", dpkgcidir, pkg->package, adminscripts[i]);
/* the full path of where we want the file to be copied to */
- dst_file = xrealloc(dst_file, strlen(infodir) + strlen(pkg->package) + strlen(adminscripts[i]) + 1);
- sprintf(dst_file, "%s%s.%s", infodir, pkg->package, adminscripts[i]);
+ dst_filename = xrealloc(dst_filename, strlen(infodir) + strlen(pkg->package) + strlen(adminscripts[i]) + 1);
+ sprintf(dst_filename, "%s%s.%s", infodir, pkg->package, adminscripts[i]);
/*
* copy admin file to permanent home
* NOTE: Maybe merge this behaviour into libb/copy_file.c
*/
- if (lstat(src_file, &src_stat_buf) == 0) {
- if ((src_fd = open(src_file, O_RDONLY)) != -1) {
- if ((dst_fd = open(dst_file, O_WRONLY | O_CREAT, 0644)) == -1) {
+ if (lstat(src_filename, &src_stat_buf) == 0) {
+ if ((src_file = wfopen(src_filename, "r")) != NULL) {
+ if ((dst_file = wfopen(dst_filename, "w")) == NULL) {
status = FALSE;
- perror_msg("Opening %s", dst_file);
+ perror_msg("Opening %s", dst_filename);
}
- copy_file_chunk(src_fd, dst_fd, src_stat_buf.st_size);
- close(src_fd);
- close(dst_fd);
+ copy_file_chunk(src_file, dst_file, src_stat_buf.st_size);
+ fclose(src_file);
+ fclose(dst_file);
} else {
status = FALSE;
- error_msg("couldnt open [%s]\n", src_file);
+ error_msg("couldnt open [%s]\n", src_filename);
}
}
}
@@ -671,7 +671,7 @@ static int dpkg_unpackcontrol(package_t *pkg)
strcat(tmp_name, pkg->package);
/* extract control.tar.gz to the full extraction path */
- deb_extract(dpkg_deb_control, tmp_name, pkg->file);
+ deb_extract(pkg->file, dpkg_deb_control, tmp_name);
/* parse the extracted control file */
strcat(tmp_name, "/control");
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c
index 450b04b..3cdd4ff 100644
--- a/archival/dpkg_deb.c
+++ b/archival/dpkg_deb.c
@@ -68,7 +68,7 @@ extern int dpkg_deb_main(int argc, char **argv)
strcpy(target_dir, argv[optind + 1]);
}
}
- deb_extract(optflag, target_dir, argv[optind]);
+ deb_extract(argv[optind], optflag, target_dir);
/* else if (optflag & dpkg_deb_info) {
extract_flag = TRUE;
extract_to_stdout = TRUE;