[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ale] gzread return -1
- Subject: [ale] gzread return -1
- From: debian4tux at telocity.com (Mark Hurley)
- Date: Fri, 4 Jan 2002 22:41:39 -0500
On Fri, Jan 04, 2002 at 09:21:02PM -0500, Chris Fowler wrote:
> I've narrowd it down. When I create a compressed file with cruch I get a
> Z_DATA_ERROR when using uncrunch. Maybe my grasp of zlib sucks.
Chris,
Nope your code worked for me. Umm...I only changed the error
output (fprintf).
Check out the code... (attached)
Mark Hurley
#include <unistd.h>
#include <zlib.h>
#include <fcntl.h>
#include <stdio.h>
int
main(int argc, char *argv[])
{
gzFile *gp;
char buffer[1024];
int n = 0;
int fd;
if(argc != 3) {
/* msgquit("crunch [source] [target]\n");*/
fprintf(stderr, "crunch [source] [target]\n");
return (1);
}
if((gp = gzopen(argv[2], "wb9")) == NULL) {
/* err_quit("open target");*/
fprintf(stderr, "open target");
return (1);
}
if((fd = open(argv[1], O_RDONLY)) == -1) {
/* err_quit("open source");*/
fprintf(stderr, "open source");
return (1);
}
while((n = read(fd, buffer, 1024)) != 0)
{
if(n < 0) {
/* err_quit("read");*/
fprintf(stderr,"read");
return (1);
}
gzwrite(gp, buffer, n);
}
close(fd);
gzclose(gp);
return 0;
}
#include <stdio.h>
#include <unistd.h>
#include <zlib.h>
#include <fcntl.h>
int
main(int argc, char *argv[])
{
gzFile *gp;
char buffer[1024];
int n = 0;
int fd;
int gzerr;
if(argc != 3) {
/* msgquit("crunch [source] [target]\n");*/
fprintf(stderr, "cruncth [source] [target]\n");
return (1);
}
if((gp = gzopen(argv[1], "rb9")) == NULL) {
/* err_quit("open target");*/
fprintf(stderr, "open target");
return (1);
}
if((fd = open(argv[2], O_WRONLY | O_TRUNC | O_CREAT, 0600)) == -1) {
/* err_quit("open source"); */
fprintf(stderr, "open source");
return (1);
}
while((n = gzread(gp, buffer, 1024)) != 0)
{
if(n < 0) {
/* err_quit("read %s", gzerror(gp, &gzerr));*/
fprintf(stderr, "read %s", gzerror(gp, &gzerr));
return (1);
}
write(fd, buffer, n);
}
close(fd);
gzclose(gp);
return 0;
}
---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.