version 1.4, 2004/05/25 04:34:40 |
version 1.5, 2004/08/30 14:36:51 |
Line 132 zuncompress(FILE *in, FILE *out, char *p |
|
Line 132 zuncompress(FILE *in, FILE *out, char *p |
|
off_t *compressed_bytes) |
off_t *compressed_bytes) |
{ |
{ |
off_t bin, bout = 0; |
off_t bin, bout = 0; |
char buf[BUFSIZE]; |
char *buf; |
|
|
|
buf = malloc(BUFSIZE); |
|
if (buf == NULL) |
|
return -1; |
|
|
/* XXX */ |
/* XXX */ |
compressed_prelen = prelen; |
compressed_prelen = prelen; |
Line 142 zuncompress(FILE *in, FILE *out, char *p |
|
Line 146 zuncompress(FILE *in, FILE *out, char *p |
|
compressed_pre = NULL; |
compressed_pre = NULL; |
|
|
while ((bin = fread(buf, 1, sizeof(buf), in)) != 0) { |
while ((bin = fread(buf, 1, sizeof(buf), in)) != 0) { |
if (fwrite(buf, 1, bin, out) != bin) |
if (fwrite(buf, 1, bin, out) != bin) { |
|
free(buf); |
return -1; |
return -1; |
|
} |
bout += bin; |
bout += bin; |
} |
} |
|
|
if (compressed_bytes) |
if (compressed_bytes) |
*compressed_bytes = total_compressed_bytes; |
*compressed_bytes = total_compressed_bytes; |
|
|
|
free(buf); |
return bout; |
return bout; |
} |
} |
|
|
|
static int |
|
zclose(void *zs) |
|
{ |
|
free(zs); |
|
/* We leave the caller to close the fd passed to zdopen() */ |
|
return 0; |
|
} |
|
|
FILE * |
FILE * |
zopen(const char *fname, FILE *preopen) |
zdopen(int fd) |
{ |
{ |
struct s_zstate *zs; |
struct s_zstate *zs; |
|
|
Line 179 zopen(const char *fname, FILE *preopen) |
|
Line 194 zopen(const char *fname, FILE *preopen) |
|
* Layering compress on top of stdio in order to provide buffering, |
* Layering compress on top of stdio in order to provide buffering, |
* and ensure that reads and write work with the data specified. |
* and ensure that reads and write work with the data specified. |
*/ |
*/ |
if ((zs->zs_fp = preopen) == NULL && |
if ((zs->zs_fp = fdopen(fd, "r")) == NULL) { |
(zs->zs_fp = fopen(fname, "r")) == NULL) { |
|
free(zs); |
free(zs); |
return NULL; |
return NULL; |
} |
} |
|
|
return fropen(zs, zread); |
return funopen(zs, zread, NULL, NULL, zclose); |
} |
} |
|
|
/* |
/* |