diff options
author | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-13 04:02:57 +0000 |
---|---|---|
committer | Glenn L McGrath <bug1@ihug.co.nz> | 2001-04-13 04:02:57 +0000 |
commit | 445fb952b8becc78889d3079e3053f76aa2eba9c (patch) | |
tree | feda0730549303c7fadd259741bea57207e46431 /libbb/untar.c | |
parent | 1e04ea388f5f673f44503052d0f8873e4017abc3 (diff) | |
download | busybox-w32-445fb952b8becc78889d3079e3053f76aa2eba9c.tar.gz busybox-w32-445fb952b8becc78889d3079e3053f76aa2eba9c.tar.bz2 busybox-w32-445fb952b8becc78889d3079e3053f76aa2eba9c.zip |
dpkg-deb -f and partial -I commands, adds 600 bytes
Diffstat (limited to '')
-rw-r--r-- | libbb/untar.c | 66 |
1 files changed, 36 insertions, 30 deletions
diff --git a/libbb/untar.c b/libbb/untar.c index d3e424e25..b768c0be8 100644 --- a/libbb/untar.c +++ b/libbb/untar.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include <unistd.h> | 22 | #include <unistd.h> |
23 | #include "libbb.h" | 23 | #include "libbb.h" |
24 | 24 | ||
25 | extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | 25 | extern int untar(FILE *src_tar_file, const int untar_function, const char *argument) |
26 | { | 26 | { |
27 | typedef struct raw_tar_header { | 27 | typedef struct raw_tar_header { |
28 | char name[100]; /* 0-99 */ | 28 | char name[100]; /* 0-99 */ |
@@ -101,37 +101,18 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
101 | if (size % 512 != 0) { | 101 | if (size % 512 != 0) { |
102 | next_header_offset += (512 - size % 512); | 102 | next_header_offset += (512 - size % 512); |
103 | } | 103 | } |
104 | /* | ||
105 | * seek to start of control file, return length | ||
106 | * | ||
107 | if (dpkg_untar_function & dpkg_untar_seek_control) { | ||
108 | if ((raw_tar_header.typeflag == '0') || (raw_tar_header.typeflag == '\0')) { | ||
109 | char *tar_filename; | ||
110 | |||
111 | tar_filename = strrchr(raw_tar_header.name, '/'); | ||
112 | if (tar_filename == NULL) { | ||
113 | tar_filename = strdup(raw_tar_header.name); | ||
114 | } else { | ||
115 | tar_filename++; | ||
116 | } | ||
117 | |||
118 | if (strcmp(tar_filename, "control") == 0) { | ||
119 | return(size); | ||
120 | } | ||
121 | } | ||
122 | 104 | ||
123 | } | ||
124 | */ | ||
125 | if (untar_function & (extract_contents | extract_verbose_extract)) { | 105 | if (untar_function & (extract_contents | extract_verbose_extract)) { |
126 | printf("%s\n", raw_tar_header.name); | 106 | printf("%s\n", raw_tar_header.name); |
127 | } | 107 | } |
128 | 108 | ||
129 | /* extract files */ | 109 | /* extract files */ |
130 | if (base_path != NULL) { | 110 | if (untar_function & (extract_extract | extract_verbose_extract | extract_control)) { |
131 | dir = xmalloc(strlen(raw_tar_header.name) + strlen(base_path) + 2); | 111 | dir = xmalloc(strlen(raw_tar_header.name) + strlen(argument) + 2); |
132 | sprintf(dir, "%s/%s", base_path, raw_tar_header.name); | 112 | sprintf(dir, "%s/%s", argument, raw_tar_header.name); |
133 | create_path(dir, 0777); | 113 | create_path(dir, 0777); |
134 | } | 114 | } |
115 | |||
135 | switch (raw_tar_header.typeflag ) { | 116 | switch (raw_tar_header.typeflag ) { |
136 | case '0': | 117 | case '0': |
137 | case '\0': | 118 | case '\0': |
@@ -145,14 +126,28 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
145 | uncompressed_count += size; | 126 | uncompressed_count += size; |
146 | fclose(dst_file); | 127 | fclose(dst_file); |
147 | } | 128 | } |
148 | while (uncompressed_count < next_header_offset) { | 129 | else if (untar_function & extract_info) { |
149 | if (fgetc(src_tar_file) == EOF) { | 130 | if (strstr(raw_tar_header.name, argument) != NULL) { |
150 | perror_msg("untar"); | 131 | copy_file_chunk(src_tar_file, stdout, (unsigned long long) size); |
151 | break; | 132 | uncompressed_count += size; |
133 | } | ||
134 | } | ||
135 | else if (untar_function & extract_field) { | ||
136 | if (strstr(raw_tar_header.name, "./control") != NULL) { | ||
137 | char *line; | ||
138 | while ((line = get_line_from_file(src_tar_file)) != NULL) { | ||
139 | uncompressed_count += strlen(line); | ||
140 | if (argument == NULL) { | ||
141 | printf("%s",line); | ||
142 | } | ||
143 | else if (strncmp(line, argument, strlen(argument)) == 0) { | ||
144 | char *file_ptr; | ||
145 | file_ptr = strstr(line, ": "); | ||
146 | printf("%s", file_ptr + 2); | ||
147 | } | ||
148 | } | ||
152 | } | 149 | } |
153 | uncompressed_count++; | ||
154 | } | 150 | } |
155 | uncompressed_count += size; | ||
156 | break; | 151 | break; |
157 | } | 152 | } |
158 | case '5': | 153 | case '5': |
@@ -193,6 +188,17 @@ extern int untar(FILE *src_tar_file, int untar_function, char *base_path) | |||
193 | free(dir); | 188 | free(dir); |
194 | return(EXIT_FAILURE); | 189 | return(EXIT_FAILURE); |
195 | } | 190 | } |
191 | |||
192 | /* | ||
193 | * Seek to start of next block, cant use fseek as unzip() does support it | ||
194 | */ | ||
195 | while (uncompressed_count < next_header_offset) { | ||
196 | if (fgetc(src_tar_file) == EOF) { | ||
197 | break; | ||
198 | } | ||
199 | uncompressed_count++; | ||
200 | } | ||
201 | |||
196 | // free(dir); | 202 | // free(dir); |
197 | } | 203 | } |
198 | return(EXIT_SUCCESS); | 204 | return(EXIT_SUCCESS); |