summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/mar
diff options
context:
space:
mode:
authorGuillaume Cottenceau <gc@mandriva.com>2000-11-20 15:21:31 +0000
committerGuillaume Cottenceau <gc@mandriva.com>2000-11-20 15:21:31 +0000
commitcbebfe6209cf200673bf91695e520124e4fd9134 (patch)
tree8735d35006a680e646c5fe9909aee0f74c8dfb08 /mdk-stage1/mar
parent0dfe6bc6726c5a70f963e575c7dc5f8c481d6d90 (diff)
downloaddrakx-backup-do-not-use-cbebfe6209cf200673bf91695e520124e4fd9134.tar
drakx-backup-do-not-use-cbebfe6209cf200673bf91695e520124e4fd9134.tar.gz
drakx-backup-do-not-use-cbebfe6209cf200673bf91695e520124e4fd9134.tar.bz2
drakx-backup-do-not-use-cbebfe6209cf200673bf91695e520124e4fd9134.tar.xz
drakx-backup-do-not-use-cbebfe6209cf200673bf91695e520124e4fd9134.zip
commiting modifs of Fri 17 (do not typedef the structs anymore, s/malloc/alloca when possible, return int all the time)
Diffstat (limited to 'mdk-stage1/mar')
-rw-r--r--mdk-stage1/mar/Makefile22
-rw-r--r--mdk-stage1/mar/mar-extract-only.c35
-rw-r--r--mdk-stage1/mar/mar-extract-only.h6
-rw-r--r--mdk-stage1/mar/mar-frontend.c32
-rw-r--r--mdk-stage1/mar/mar.h12
5 files changed, 68 insertions, 39 deletions
diff --git a/mdk-stage1/mar/Makefile b/mdk-stage1/mar/Makefile
index 6f87681f7..c35f50f02 100644
--- a/mdk-stage1/mar/Makefile
+++ b/mdk-stage1/mar/Makefile
@@ -1,3 +1,23 @@
+ #******************************************************************************
+ #
+ # mar - The Mandrake Archiver
+ #
+ # $Id$
+ #
+ # 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.
+ #
+ #*****************************************************************************
+
+
all: mar
clean:
@@ -9,7 +29,7 @@ FLAGS = -Wall -Werror -Os -fomit-frame-pointer -c
mar: mar-frontend.o mar-extract-only.o
gcc -o mar mar-frontend.o mar-extract-only.o -lz
-mar-frontend.o: mar-frontend.c mar.h
+mar-frontend.o: mar-frontend.c mar.h mar-extract-only.h
gcc $(FLAGS) mar-frontend.c
mar-extract-only.o: mar-extract-only.c mar-extract-only.h mar.h
diff --git a/mdk-stage1/mar/mar-extract-only.c b/mdk-stage1/mar/mar-extract-only.c
index 097ac4cb0..3627e84bb 100644
--- a/mdk-stage1/mar/mar-extract-only.c
+++ b/mdk-stage1/mar/mar-extract-only.c
@@ -34,7 +34,7 @@ gzerr(gzFile f) /* decrease code size */
}
int
-calc_integrity(mar_stream *s)
+calc_integrity(struct mar_stream *s)
{
char buf[4096];
int current_crc = 0;
@@ -64,9 +64,9 @@ calc_integrity(mar_stream *s)
int
-extract_file(mar_stream *s, char *filename, char *dest_dir)
+extract_file(struct mar_stream *s, char *filename, char *dest_dir)
{
- mar_element * elem = s->first_element;
+ struct mar_element * elem = s->first_element;
while (elem)
{
if (strcmp(elem->filename, filename) == 0)
@@ -74,7 +74,7 @@ extract_file(mar_stream *s, char *filename, char *dest_dir)
char *buf;
char *dest_file;
int fd;
- dest_file = (char *) malloc(strlen(dest_dir) + strlen(filename) + 1);
+ dest_file = (char *) alloca(strlen(dest_dir) + strlen(filename) + 1);
strcpy(dest_file, dest_dir);
strcat(dest_file, filename);
fd = creat(dest_file, 00660);
@@ -83,7 +83,7 @@ extract_file(mar_stream *s, char *filename, char *dest_dir)
perror(dest_file);
return -1;
}
- buf = (char *) malloc(elem->file_length);
+ buf = (char *) alloca(elem->file_length);
if (!buf)
{
perror(dest_file);
@@ -113,26 +113,25 @@ extract_file(mar_stream *s, char *filename, char *dest_dir)
}
-mar_stream *
-open_marfile(char *filename)
+int
+open_marfile(char *filename, struct mar_stream *s)
{
int end_filetable = 0;
- mar_stream * s = (mar_stream *) malloc(sizeof(mar_stream));
- mar_element * previous_element = NULL;
+ struct mar_element * previous_element = NULL;
/* mar_gzfile */
s->mar_gzfile = gzopen(filename, "rb");
if (!s->mar_gzfile)
{
perror(filename);
- return NULL;
+ return -1;
}
/* crc32 */
if (gzread(s->mar_gzfile, &(s->crc32), sizeof(int)) != sizeof(int))
{
gzerr(s->mar_gzfile);
- return NULL;
+ return -1;
}
DEBUG_MAR(printf("D: mar::open_marfile crc-in-marfile %d\n", s->crc32););
@@ -140,13 +139,13 @@ open_marfile(char *filename)
if (s->crc32 != calc_integrity(s))
{
fprintf(stderr, "E: mar::open_marfile CRC check failed\n");
- return NULL;
+ return -1;
}
else
if (gzseek(s->mar_gzfile, sizeof(int), SEEK_SET) != sizeof(int))
{
gzerr(s->mar_gzfile);
- return NULL;
+ return -1;
}
while (end_filetable == 0)
@@ -159,27 +158,27 @@ open_marfile(char *filename)
if (gzread(s->mar_gzfile, &(buf[ptr]), sizeof(char)) != sizeof(char))
{
gzerr(s->mar_gzfile);
- return NULL;
+ 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)
{
- mar_element * e = (mar_element *) malloc(sizeof(mar_element));
+ struct mar_element * e = (struct mar_element *) malloc(sizeof(struct mar_element));
e->filename = strdup(buf);
DEBUG_MAR(printf("D: mar::open_marfile processing-file %s\n", e->filename););
/* read file_length */
if (gzread(s->mar_gzfile, &(e->file_length), sizeof(int)) != sizeof(int))
{
gzerr(s->mar_gzfile);
- return NULL;
+ return -1;
}
/* read data_offset */
if (gzread(s->mar_gzfile, &(e->data_offset), sizeof(int)) != sizeof(int))
{
gzerr(s->mar_gzfile);
- return NULL;
+ return -1;
}
/* write down chaining */
if (previous_element)
@@ -195,6 +194,6 @@ open_marfile(char *filename)
/* chaining for last element */
previous_element->next_element = NULL;
- return s;
+ return 0;
}
diff --git a/mdk-stage1/mar/mar-extract-only.h b/mdk-stage1/mar/mar-extract-only.h
index 5f3280a19..f5db6c183 100644
--- a/mdk-stage1/mar/mar-extract-only.h
+++ b/mdk-stage1/mar/mar-extract-only.h
@@ -28,8 +28,8 @@
#include "mar.h"
-mar_stream * open_marfile(char *filename);
-int extract_file(mar_stream *s, char *filename, char *dest_dir);
-int calc_integrity(mar_stream *s);
+int open_marfile(char *filename, struct mar_stream *s);
+int extract_file(struct mar_stream *s, char *filename, char *dest_dir);
+int calc_integrity(struct mar_stream *s);
#endif
diff --git a/mdk-stage1/mar/mar-frontend.c b/mdk-stage1/mar/mar-frontend.c
index ae9338f91..55550d8a1 100644
--- a/mdk-stage1/mar/mar-frontend.c
+++ b/mdk-stage1/mar/mar-frontend.c
@@ -28,9 +28,9 @@
#include "mar-extract-only.h"
void
-list_files(mar_stream *s)
+list_files(struct mar_stream *s)
{
- mar_element * elem = s->first_element;
+ struct mar_element * elem = s->first_element;
printf("%-20s%8s\n", "FILENAME", "LENGTH");
while (elem)
{
@@ -86,7 +86,7 @@ create_marfile(char *dest_file, char **files)
total_length += fsiz;
filenum++;
}
- temp_marfile_buffer = (char *) malloc(total_length); /* create the whole file in-memory */
+ temp_marfile_buffer = (char *) alloca(total_length); /* create the whole file in-memory */
DEBUG_MAR(printf("D: mar::create_marfile total-length %d\n", total_length););
current_offset_filetable = sizeof(int); /* first file is after the crc */
@@ -178,11 +178,14 @@ main(int argc, char **argv)
{
if (strcmp(argv[1], "-l") == 0)
{
- mar_stream *s = open_marfile(argv[2]);
- if (!s)
+ struct mar_stream s;
+ if (open_marfile(argv[2], &s) != 0)
+ {
+ fprintf(stderr, "E: open-marfile-failed\n");
exit(-1);
- list_files(s);
- if (s->crc32 == calc_integrity(s))
+ }
+ list_files(&s);
+ if (s.crc32 == calc_integrity(&s))
printf("CRC OK\n");
else
printf("CRC FAILED!\n");
@@ -190,13 +193,13 @@ main(int argc, char **argv)
}
if ((strcmp(argv[1], "-x") == 0) && argc >= 4)
{
- mar_stream *s = open_marfile(argv[2]);
+ struct mar_stream s;
int i = 3;
- if (!s)
+ if (open_marfile(argv[2], &s) != 0)
exit(-1);
while (i < argc)
{
- int res = extract_file(s, argv[i], "./");
+ int res = extract_file(&s, argv[i], "./");
if (res == 1)
fprintf(stderr, "W: file-not-found-in-archive %s\n", argv[i]);
if (res == -1)
@@ -215,7 +218,14 @@ main(int argc, char **argv)
i++;
}
files[argc-3] = NULL;
- exit(create_marfile(argv[2], files));
+ {
+ int results;
+ results = create_marfile(argv[2], files);
+ if (results != 0)
+ fprintf(stderr, "E: create-marfile-failed\n");
+ exit(results);
+ }
+
}
}
diff --git a/mdk-stage1/mar/mar.h b/mdk-stage1/mar/mar.h
index a5ea62aa0..bd731770b 100644
--- a/mdk-stage1/mar/mar.h
+++ b/mdk-stage1/mar/mar.h
@@ -53,20 +53,20 @@
*
*/
-typedef struct mar_element_s
+struct mar_element
{
char * filename; /* filename (ASCIIZ) of the element */
int file_length; /* length (in bytes) of the raw data of the element */
int data_offset; /* seek start of the raw data in the underlying mar stream */
- struct mar_element_s * next_element; /* pointer to the next element in the mar stream; NULL if last */
-} mar_element;
+ struct mar_element * next_element; /* pointer to the next element in the mar stream; NULL if last */
+};
-typedef struct mar_stream_s
+struct mar_stream
{
int crc32; /* crc32 of the mar stream; it is the addition of all the 8-bit char's from the stream */
- mar_element * first_element; /* pointer to the first element inside the mar stream */
+ struct mar_element * first_element; /* pointer to the first element inside the mar stream */
gzFile mar_gzfile; /* associated gzFile (opened) */
-} mar_stream;
+};
int gz_errnum;