Hi, some things:
* I'm making a Debian package of gzrt (http://bugs.debian.org/378112) * gcc 4.1 produces some warnings, the attached patch fixes them * I've written a manual page for gzrecover (attached) * I've re-written the Makefile so it respects CFLAGS (attached) * Would it be possible for you to split the compile/install instructions out of the README, into README.build or something? * The copyright date in the source file needs updating, since the years are different to the ones in the README. * Your ChangeLog should probably be renamed to NEWS I place the patch, manual page and Makefile in the public domain, please integrate them and take copyright of them. -- bye, pabs http://wiki.debian.org/PaulWise
--- gzrecover.c.orig 2005-11-13 07:07:59.000000000 +0800 +++ gzrecover.c 2006-07-13 20:49:46.000000000 +0800 @@ -25,6 +25,7 @@ #include <errno.h> #include <fcntl.h> #include <unistd.h> +#include <string.h> #include <zlib.h> /* Global contants */ @@ -50,16 +51,7 @@ exit(exit_status); } -/* Check system call error status */ -void -check_error(int badcode, int rc, const char* callname) -{ - if (rc == badcode) - { - perror(callname); - exit(1); - } -} +#define throw_error(callname) perror(callname); exit(1); /* Read bytes from a file - restart on EINTR */ ssize_t @@ -86,9 +78,10 @@ /* Build the output file name */ if (outfile_specified) - check_error(0, outfile = (char *)malloc(strlen(user_outname) + 9), "malloc"); + outfile = (char *)malloc(strlen(user_outname) + 9); else - check_error(0, outfile = (char *)malloc(strlen(infile) + 25), "malloc"); + outfile = (char *)malloc(strlen(infile) + 25); + if( outfile == 0 ){ throw_error("malloc") } if (!outfile_specified) /* Strip of .gz unless user specified name */ { @@ -111,8 +104,8 @@ sprintf(outfile, "%s.recovered", infile); /* Open it up */ - check_error(-1, ofd = open(outfile, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR), - "open"); + ofd = open(outfile, O_RDWR | O_CREAT, S_IWUSR | S_IRUSR); + if( ofd == -1 ){ throw_error("open") } if (verbose_mode) fprintf(stdout, "Opened output file for writing: %s\n", outfile); @@ -122,7 +115,7 @@ /* Initialize the zlib decompression engine */ void -init_zlib(z_stream *d_stream, char *buffer, size_t bufsize) +init_zlib(z_stream *d_stream, unsigned char *buffer, size_t bufsize) { int rc; @@ -189,7 +182,8 @@ int opt, rc, ifd, ofd, founderr=0, foundgood=0; ssize_t bytes_read=0; off_t errpos=0, errinc=0; - char *infile, *inbuf, *outbuf; + char *infile; + unsigned char *inbuf, *outbuf; z_stream d_stream; /* Parse options */ @@ -223,18 +217,22 @@ infile = argv[optind]; /* Open input file and memory map */ - check_error(0, inbuf = (char *)malloc(inbuf_size), "malloc"); - check_error(-1, ifd = open(infile, O_RDONLY), "open"); + inbuf = (unsigned char *)malloc(inbuf_size); + if( inbuf == 0 ){ throw_error("malloc") } + ifd = open(infile, O_RDONLY); + if( ifd == -1 ){ throw_error("open") } if (verbose_mode) fprintf(stdout, "Opened input file for reading: %s\n", infile); /* Open output file & initialize output buffer */ ofd = open_outfile(infile); - check_error(0, outbuf = (char *)malloc(outbuf_size), "malloc"); + outbuf = (unsigned char *)malloc(outbuf_size); + if( outbuf == 0 ){ throw_error("malloc") } /* Initialize zlib */ - check_error(-1, bytes_read = read_internal(ifd, inbuf, inbuf_size), "read"); + bytes_read = read_internal(ifd, inbuf, inbuf_size); + if( -1 == bytes_read ){ throw_error("read") } if (bytes_read == 0) { if (verbose_mode) @@ -270,8 +268,8 @@ if (d_stream.avail_in == 0) { - check_error(-1, bytes_read = read_internal(ifd, inbuf, - inbuf_size), "read"); + bytes_read = read_internal(ifd, inbuf, inbuf_size); + if( bytes_read == -1 ){ throw_error("read") } if (bytes_read == 0) break; @@ -283,7 +281,7 @@ if (verbose_mode) fprintf(stdout, "Found error at byte %d in input stream\n", - errpos); + (int)errpos); } inflateEnd(&d_stream); @@ -300,7 +298,7 @@ errinc = 0; if (verbose_mode) fprintf(stdout, "Found good data at byte %d in input stream\n", - errpos + errinc); + (int)(errpos + errinc)); if (split_mode) { @@ -310,15 +308,14 @@ } /* Write decompressed output - should really handle short write counts */ - check_error(-1, write(ofd, outbuf, outbuf_size - d_stream.avail_out), - "write"); + if( -1 == write(ofd, outbuf, outbuf_size - d_stream.avail_out) ){ throw_error("write") } fsync(ofd); /* We've exhausted our input buffer, read some more */ if (d_stream.avail_in == 0) { - check_error(-1, bytes_read = read_internal(ifd, inbuf, - inbuf_size), "read"); + bytes_read = read_internal(ifd, inbuf, inbuf_size); + if( bytes_read == -1 ){ perror("read"); exit(1); } if (bytes_read == 0) break; @@ -338,7 +335,7 @@ inbuf_size - d_stream.avail_in); inflateEnd(&d_stream); - if ((char *)d_stream.next_in == inbuf) + if ((unsigned char *)d_stream.next_in == inbuf) { init_zlib(&d_stream, inbuf, bytes_read); } @@ -358,7 +355,7 @@ if (verbose_mode) fprintf(stdout, "Total decompressed output = %d bytes\n", - d_stream.total_out); + (int)d_stream.total_out); return(0); }
CFLAGS += -Wall -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 LDFLAGS += -lz all: gzrecover gzrecover: gzrecover.c clean: rm gzrecover
.TH GZRT 1 "July 13, 2006" .SH NAME gzrecover \- gzip recovery toolkit .SH SYNOPSIS .B gzrecover .RI [ options ] " file" .SH DESCRIPTION \fBgzrecover\fP will attempt to skip over corrupted data in a gzip archive, allowing the remaining data to be recovered. .SH OPTIONS .TP .B \-h .br Show usage statement. .TP .B \-v .br Turn on verbose mode. .TP .B \-s .br Turn on split mode. .TP .B \-o .I file .br Set the output file. .SH SEE ALSO .BR gzip (1), .BR cpio (1). .SH AUTHOR gzrecover was written by Aaron M. Renn <[EMAIL PROTECTED]>.
signature.asc
Description: This is a digitally signed message part