extern int dpkg_deb_main(int argc, char **argv)
{
- char *target_dir = NULL;
+ char *target_dir;
int opt = 0;
int optflag = 0;
}
}
- if (((optind + 1 ) > argc) || (optflag == 0)) {
+ if (optind == argc) {
show_usage();
}
+
switch (optflag) {
case (extract_control):
case (extract_extract):
if ( (optind + 1) == argc ) {
target_dir = (char *) xmalloc(7);
strcpy(target_dir, "DEBIAN");
+ } else {
+ target_dir = (char *) xmalloc(strlen(argv[optind + 1]) + 1);
+ strcpy(target_dir, argv[optind + 1]);
}
break;
- default: {
- target_dir = (char *) xmalloc(strlen(argv[optind + 1]));
- strcpy(target_dir, argv[optind + 1]);
- }
+ default:
+ target_dir = NULL;
}
+
deb_extract(argv[optind], optflag, target_dir);
/* else if (optflag & dpkg_deb_info) {
extract_flag = TRUE;
extern int dpkg_deb_main(int argc, char **argv)
{
- char *target_dir = NULL;
+ char *target_dir;
int opt = 0;
int optflag = 0;
}
}
- if (((optind + 1 ) > argc) || (optflag == 0)) {
+ if (optind == argc) {
show_usage();
}
+
switch (optflag) {
case (extract_control):
case (extract_extract):
if ( (optind + 1) == argc ) {
target_dir = (char *) xmalloc(7);
strcpy(target_dir, "DEBIAN");
+ } else {
+ target_dir = (char *) xmalloc(strlen(argv[optind + 1]) + 1);
+ strcpy(target_dir, argv[optind + 1]);
}
break;
- default: {
- target_dir = (char *) xmalloc(strlen(argv[optind + 1]));
- strcpy(target_dir, argv[optind + 1]);
- }
+ default:
+ target_dir = NULL;
}
+
deb_extract(argv[optind], optflag, target_dir);
/* else if (optflag & dpkg_deb_info) {
extract_flag = TRUE;
size_t size;
mode_t mode;
-// signal(SIGCHLD, child_died);
-
while (fread((char *) &raw_tar_header, 1, 512, src_tar_file) == 512) {
long sum = 0;
- char *dir;
+ char *dir = NULL;
uncompressed_count += 512;
/* Check header has valid magic */
if (strncmp(raw_tar_header.magic, "ustar", 5) != 0) {
/* Put this pack after TODO (check child still alive) is done */
-// error_msg("Invalid tar magic");
+ error_msg("Invalid tar magic");
break;
}
}
*/
- /* extract files */
- dir = xmalloc(strlen(raw_tar_header.name) + strlen(base_path) + 2);
+ if (untar_function & (extract_verbose_extract | extract_contents)) {
+ printf("%s\n", raw_tar_header.name);
+ }
- sprintf(dir, "%s/%s", base_path, raw_tar_header.name);
- create_path(dir, 0777);
+ /* extract files */
+ if (base_path != NULL) {
+ dir = xmalloc(strlen(raw_tar_header.name) + strlen(base_path) + 2);
+ sprintf(dir, "%s/%s", base_path, raw_tar_header.name);
+ create_path(dir, 0777);
+ }
switch (raw_tar_header.typeflag ) {
case '0':
case '\0':
*/
if (raw_tar_header.name[strlen(raw_tar_header.name)-1] != '/') {
switch (untar_function) {
- case (extract_verbose_extract):
- printf("%s\n", raw_tar_header.name);
case (extract_extract): {
FILE *dst_file = wfopen(dir, "w");
copy_file_chunk(src_tar_file, dst_file, size);
break;
}
case '5':
- switch (untar_function) {
- case (extract_verbose_extract):
- printf("%s\n", raw_tar_header.name);
- case (extract_extract):
- if (create_path(dir, mode) != TRUE) {
- free(dir);
- perror_msg("%s: Cannot mkdir", raw_tar_header.name);
- return(EXIT_FAILURE);
- }
- break;
- default:
+ if (untar_function & (extract_extract | extract_verbose_extract)) {
+ if (create_path(dir, mode) != TRUE) {
+ free(dir);
+ perror_msg("%s: Cannot mkdir", raw_tar_header.name);
+ return(EXIT_FAILURE);
+ }
}
break;
case '1':
free(dir);
return(EXIT_FAILURE);
}
- free(dir);
+// free(dir);
}
return(EXIT_SUCCESS);
}