[ale] gzread return -1

Chris Fowler cfowler at outpostsentinel.com
Fri Jan 4 21:21:02 EST 2002


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.


cruch.c

#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;

        if(argc != 3)
                msgquit("crunch [source] [target]\n");


        if((gp = gzopen(argv[2], "wb9")) == NULL)
                err_quit("open target");


        if((fd = open(argv[1], O_RDONLY)) == -1)
                err_quit("open source");


        while((n = read(fd, buffer, 1024)) != 0)
        {
                if(n < 0)
                        err_quit("read");

                gzwrite(gp, buffer, n);
        }

        close(fd);
        gzclose(gp);

        return 0;
}

uncrunch.c

#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");


        if((gp = gzopen(argv[1], "rb9")) == NULL)
                err_quit("open target");


        if((fd = open(argv[2], O_WRONLY | O_TRUNC | O_CREAT, 0600)) == -1)
                err_quit("open source");


        while((n = gzread(gp, buffer, 1024)) != 0)
        {
                if(n < 0)
                        err_quit("read %s", gzerror(gp, &gzerr));

                write(fd, buffer, n);
        }

        close(fd);
        gzclose(gp);

        return 0;
}
-----Original Message-----
From: Mark [mailto:mph at bravo-64-128-248-9.telocity.com]On Behalf Of Mark
To: ale at ale.org
Hurley
Sent: Friday, January 04, 2002 9:18 PM
To: ale at ale.org
Subject: Re: [ale] gzread return -1


On Fri, Jan 04, 2002 at 08:06:16PM -0500, Chris Fowler wrote:
> Does anyone know why gzread() would return a -1 but errno is set to
Success?

Let me guess, it's in a VB app?

;)

Mark

---
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.




---
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.






More information about the Ale mailing list