diff options
author | Mystery Man <unknown@mandriva.org> | 2003-03-10 13:52:45 +0000 |
---|---|---|
committer | Mystery Man <unknown@mandriva.org> | 2003-03-10 13:52:45 +0000 |
commit | c7681947b501455947618f1694df12fbb3c1d367 (patch) | |
tree | f543345cc4a3834b3601cfbb2f9177782544dc79 /mdk-stage1/mar/mar-extract-only.c | |
parent | f9ef1c397c4fcb602a79ac7c0f83d938ff3597f2 (diff) | |
download | drakx-backup-do-not-use-c7681947b501455947618f1694df12fbb3c1d367.tar drakx-backup-do-not-use-c7681947b501455947618f1694df12fbb3c1d367.tar.gz drakx-backup-do-not-use-c7681947b501455947618f1694df12fbb3c1d367.tar.bz2 drakx-backup-do-not-use-c7681947b501455947618f1694df12fbb3c1d367.tar.xz drakx-backup-do-not-use-c7681947b501455947618f1694df12fbb3c1d367.zip |
This commit was manufactured by cvs2svn to create tag 'V9_1_19mdk'.V9_1_19mdk
Diffstat (limited to 'mdk-stage1/mar/mar-extract-only.c')
-rw-r--r-- | mdk-stage1/mar/mar-extract-only.c | 208 |
1 files changed, 0 insertions, 208 deletions
diff --git a/mdk-stage1/mar/mar-extract-only.c b/mdk-stage1/mar/mar-extract-only.c deleted file mode 100644 index a5b6ccd2f..000000000 --- a/mdk-stage1/mar/mar-extract-only.c +++ /dev/null @@ -1,208 +0,0 @@ -/* - * Guillaume Cottenceau (gc@mandrakesoft.com) - * - * Copyright 2000 MandrakeSoft - * - * This software may be freely redistributed under the terms of the GNU - * public license. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * - */ - -/* - * mar - The Mandrake Archiver - * - * An archiver that supports compression (through zlib). - * - */ - -/* - * This code should suffice for stage1 on-the-fly uncompression of kernel modules. - * (and it DOES perform tests and return values, blaaaah..) - */ - -#include "mar-extract-only.h" -#include "mar.h" - -#ifdef _STANDALONE_ -void -zerr(BZFILE * f) /* decrease code size */ -{ - fprintf(stderr, BZ2_bzerror(f, &z_errnum)); -} - -inline void -log_perror(char *msg) -{ - perror(msg); -} -void -log_message(char *msg) -{ - fprintf(stderr, msg); -} -#else /* _STANDALONE_ */ -#include "../log.h" -void -zerr(BZFILE * f) /* decrease code size */ -{ - log_message(BZ2_bzerror(f, &z_errnum)); -} -#endif /* _STANDALONE_ */ - - -static int -mar_open_file(char *filename, struct mar_stream *s) -{ - int end_filetable = 0; - struct mar_element * previous_element = NULL; - - /* mar_zfile */ - s->mar_zfile = BZ2_bzopen(filename, "rb"); - if (!s->mar_zfile) - { - log_perror(filename); - return -1; - } - - while (end_filetable == 0) - { - char buf[512]; - int ptr = 0; - /* read filename */ - do - { - if (BZ2_bzread(s->mar_zfile, &(buf[ptr]), sizeof(char)) != sizeof(char)) - { - zerr(s->mar_zfile); - return -1; - } - ptr++; - } while ((buf[ptr-1] != 0) && (ptr < 512)); - /* ptr == 1 when we arrive on the "char 0" of the end of the filetable */ - if (ptr > 1) - { - struct mar_element * e = (struct mar_element *) malloc(sizeof(struct mar_element)); - e->filename = strdup(buf); - /* read file_length */ - if (BZ2_bzread(s->mar_zfile, &(e->file_length), sizeof(int)) != sizeof(int)) - { - zerr(s->mar_zfile); - return -1; - } - /* read data_offset */ - if (BZ2_bzread(s->mar_zfile, &(e->data_offset), sizeof(int)) != sizeof(int)) - { - zerr(s->mar_zfile); - return -1; - } - /* write down chaining */ - if (previous_element) - previous_element->next_element = e; - else - s->first_element = e; - previous_element = e; - } - else - end_filetable = 1; - - } - /* chaining for last element */ - previous_element->next_element = NULL; - - return 0; -} - - -char ** -mar_list_contents(char * mar_filename) -{ - struct mar_stream s; - struct mar_element * elem; - char * tmp_contents[500]; - char ** answ; - int i = 0; - - if (mar_open_file(mar_filename, &s)) - return NULL; - - elem = s.first_element; - while (elem) - { - tmp_contents[i++] = strdup(elem->filename); - elem = elem->next_element; - } - tmp_contents[i++] = NULL; - answ = (char **) malloc(sizeof(char *) * i); - memcpy(answ, tmp_contents, sizeof(char *) * i); - return answ; -} - - -int -mar_extract_file(char *mar_filename, char *filename_to_extract, char *dest_dir) -{ - struct mar_stream s; - struct mar_element * elem; - - if (mar_open_file(mar_filename, &s)) - return -1; - - elem = s.first_element; - while (elem) - { - if (strcmp(elem->filename, filename_to_extract) == 0) - { - char garb_buf[4096]; - char *buf; - char *dest_file; - int fd; - size_t i; - dest_file = (char *) alloca(strlen(dest_dir) + strlen(filename_to_extract) + 1); - strcpy(dest_file, dest_dir); - strcat(dest_file, filename_to_extract); - fd = creat(dest_file, 00660); - if (fd == -1) - { - log_perror(dest_file); - return -1; - } - buf = (char *) alloca(elem->file_length); - if (!buf) - { - log_perror(dest_file); - return -1; - } - i = elem->data_offset; - while (i > 0) { - int to_read = i > sizeof(garb_buf) ? sizeof(garb_buf) : i; - if (BZ2_bzread(s.mar_zfile, garb_buf, to_read) != to_read) { - log_message("MAR: unexpected EOF in stream"); - return -1; - } - i -= to_read; - } - if (BZ2_bzread(s.mar_zfile, buf, elem->file_length) != elem->file_length) - { - zerr(s.mar_zfile); - return -1; - } - if (write(fd, buf, elem->file_length) != elem->file_length) - { - log_perror(dest_file); - return -1; - } - close(fd); /* do not check return value for code size */ - BZ2_bzclose(s.mar_zfile); - return 0; - } - elem = elem->next_element; - } - BZ2_bzclose(s.mar_zfile); - return 1; /* 1 for file_not_found_in_archive */ -} - - |