aboutsummaryrefslogtreecommitdiff
path: root/libbb/deb_extract.c
diff options
context:
space:
mode:
Diffstat (limited to 'libbb/deb_extract.c')
-rw-r--r--libbb/deb_extract.c33
1 files changed, 15 insertions, 18 deletions
diff --git a/libbb/deb_extract.c b/libbb/deb_extract.c
index b95dfa4d4..36cebfa51 100644
--- a/libbb/deb_extract.c
+++ b/libbb/deb_extract.c
@@ -34,12 +34,13 @@
34 * The contents of argument depend on the value of function. 34 * The contents of argument depend on the value of function.
35 * It is either a dir name or a control file or field name(see dpkg_deb.c) 35 * It is either a dir name or a control file or field name(see dpkg_deb.c)
36 */ 36 */
37extern int deb_extract(const char *package_filename, int function, char *argument) 37extern char *deb_extract(const char *package_filename, const int function, const char *argument, const char *argument2)
38{ 38{
39 39
40 FILE *deb_file, *uncompressed_file; 40 FILE *deb_file, *uncompressed_file;
41 ar_headers_t *headers = NULL; 41 ar_headers_t *headers = NULL;
42 char *ared_file = NULL; 42 char *ared_file = NULL;
43 char *output_buffer = NULL;
43 int gunzip_pid; 44 int gunzip_pid;
44 45
45 switch (function) { 46 switch (function) {
@@ -61,7 +62,7 @@ extern int deb_extract(const char *package_filename, int function, char *argumen
61 /* get a linked list of all ar entries */ 62 /* get a linked list of all ar entries */
62 if ((headers = get_ar_headers(deb_file)) == NULL) { 63 if ((headers = get_ar_headers(deb_file)) == NULL) {
63 error_msg("Couldnt get ar headers\n"); 64 error_msg("Couldnt get ar headers\n");
64 return(EXIT_FAILURE); 65 return(NULL);
65 } 66 }
66 67
67 /* seek to the start of the .tar.gz file within the ar file*/ 68 /* seek to the start of the .tar.gz file within the ar file*/
@@ -75,27 +76,23 @@ extern int deb_extract(const char *package_filename, int function, char *argumen
75 if (function & extract_fsys_tarfile) { 76 if (function & extract_fsys_tarfile) {
76 copy_file_chunk(uncompressed_file, stdout, -1); 77 copy_file_chunk(uncompressed_file, stdout, -1);
77 } else { 78 } else {
78 char *output_buffer = NULL; 79 FILE *output;
79 output_buffer = untar(uncompressed_file, stdout, function, argument); 80
80 if (function & extract_field) { 81 if (function & extract_contents_to_file) {
81 char *field = NULL; 82 output = wfopen(argument, "w");
82 int field_length = 0; 83 } else {
83 int field_start = 0; 84 output = stdout;
84 while ((field = read_package_field(&output_buffer[field_start])) != NULL) {
85 field_length = strlen(field);
86 field_start += (field_length + 1);
87 if (strstr(field, argument) == field) {
88 printf("%s\n", field + strlen(argument) + 2);
89 }
90 free(field);
91 }
92 } 85 }
93 }
94 86
87 output_buffer = untar(uncompressed_file, output, function, argument, argument2);
88 if (output != stdout) {
89 fclose(output);
90 }
91 }
95 gz_close(gunzip_pid); 92 gz_close(gunzip_pid);
96 fclose(deb_file); 93 fclose(deb_file);
97 fclose(uncompressed_file); 94 fclose(uncompressed_file);
98 free(ared_file); 95 free(ared_file);
99 96
100 return(EXIT_SUCCESS); 97 return(output_buffer);
101} \ No newline at end of file 98} \ No newline at end of file