version 1.6, 2003/06/03 21:08:36 |
version 1.7, 2003/06/22 15:22:43 |
|
|
static int get_byte(gz_stream *); |
static int get_byte(gz_stream *); |
|
|
int |
int |
gz_check_header(fd, sb, ofn) |
gz_check_header(int fd, struct stat *sb, const char *ofn) |
int fd; |
|
struct stat *sb; |
|
const char *ofn; |
|
{ |
{ |
int f; |
int f; |
u_char buf[sizeof(gz_magic)]; |
u_char buf[sizeof(gz_magic)]; |
off_t off = lseek(fd, 0, SEEK_CUR); |
off_t off = lseek(fd, 0, SEEK_CUR); |
|
|
f = (read(fd, buf, sizeof(buf)) == sizeof(buf) && |
f = (read(fd, buf, sizeof(buf)) == sizeof(buf) && |
!memcmp(buf, gz_magic, sizeof(buf))); |
!memcmp(buf, gz_magic, sizeof(buf))); |
|
|
lseek (fd, off, SEEK_SET); |
lseek (fd, off, SEEK_SET); |
|
|
|
|
} |
} |
|
|
void * |
void * |
gz_open (fd, mode, bits) |
gz_open(int fd, const char *mode, int bits) |
int fd; |
|
const char *mode; |
|
int bits; |
|
{ |
{ |
gz_stream *s; |
gz_stream *s; |
|
|
|
|
} |
} |
|
|
int |
int |
gz_close (cookie) |
gz_close(void *cookie) |
void *cookie; |
|
{ |
{ |
gz_stream *s = (gz_stream*)cookie; |
gz_stream *s = (gz_stream*)cookie; |
int err = 0; |
int err = 0; |
|
|
} |
} |
|
|
int |
int |
gz_flush (cookie, flush) |
gz_flush(void *cookie, int flush) |
void *cookie; |
|
int flush; |
|
{ |
{ |
gz_stream *s = (gz_stream*)cookie; |
gz_stream *s = (gz_stream*)cookie; |
size_t len; |
size_t len; |
|
|
} |
} |
|
|
static int |
static int |
put_int32 (s, x) |
put_int32(gz_stream *s, u_int32_t x) |
gz_stream *s; |
|
u_int32_t x; |
|
{ |
{ |
if (write(s->z_fd, &x, 1) != 1) |
if (write(s->z_fd, &x, 1) != 1) |
return Z_ERRNO; |
return Z_ERRNO; |
|
|
} |
} |
|
|
static int |
static int |
get_byte(s) |
get_byte(gz_stream *s) |
gz_stream *s; |
|
{ |
{ |
if (s->z_eof) |
if (s->z_eof) |
return EOF; |
return EOF; |
|
|
} |
} |
|
|
static u_int32_t |
static u_int32_t |
get_int32 (s) |
get_int32(gz_stream *s) |
gz_stream *s; |
|
{ |
{ |
u_int32_t x; |
u_int32_t x; |
|
|
|
|
} |
} |
|
|
static int |
static int |
get_header(s) |
get_header(gz_stream *s) |
gz_stream *s; |
|
{ |
{ |
int method; /* method byte */ |
int method; /* method byte */ |
int flags; /* flags byte */ |
int flags; /* flags byte */ |
|
|
} |
} |
|
|
int |
int |
gz_read(cookie, buf, len) |
gz_read(void *cookie, char *buf, int len) |
void *cookie; |
|
char *buf; |
|
int len; |
|
{ |
{ |
gz_stream *s = (gz_stream*)cookie; |
gz_stream *s = (gz_stream*)cookie; |
u_char *start = buf; /* starting point for crc computation */ |
u_char *start = buf; /* starting point for crc computation */ |
|
|
|
|
errno = 0; |
errno = 0; |
if ((s->z_stream.avail_in = |
if ((s->z_stream.avail_in = |
read(s->z_fd, s->z_buf, Z_BUFSIZE)) == 0) |
read(s->z_fd, s->z_buf, Z_BUFSIZE)) == 0) |
s->z_eof = 1; |
s->z_eof = 1; |
s->z_stream.next_in = s->z_buf; |
s->z_stream.next_in = s->z_buf; |
} |
} |
|
|
if (inflate(&(s->z_stream), Z_NO_FLUSH) == Z_STREAM_END) { |
if (inflate(&(s->z_stream), Z_NO_FLUSH) == Z_STREAM_END) { |
/* Check CRC and original size */ |
/* Check CRC and original size */ |
s->z_crc = crc32(s->z_crc, start, |
s->z_crc = crc32(s->z_crc, start, |
(uInt)(s->z_stream.next_out - start)); |
(uInt)(s->z_stream.next_out - start)); |
start = s->z_stream.next_out; |
start = s->z_stream.next_out; |
|
|
if (get_int32(s) != s->z_crc || |
if (get_int32(s) != s->z_crc || |
get_int32(s) != s->z_stream.total_out) { |
get_int32(s) != s->z_stream.total_out) { |
errno = EIO; |
errno = EIO; |
return -1; |
return -1; |
} |
} |
s->z_eof = 1; |
s->z_eof = 1; |
|
|
} |
} |
} |
} |
s->z_crc = crc32(s->z_crc, start, |
s->z_crc = crc32(s->z_crc, start, |
(uInt)(s->z_stream.next_out - start)); |
(uInt)(s->z_stream.next_out - start)); |
|
|
return (int)(len - s->z_stream.avail_out); |
return (int)(len - s->z_stream.avail_out); |
} |
} |
|
|
int |
int |
gz_write(cookie, buf, len) |
gz_write(void *cookie, const char *buf, int len) |
void *cookie; |
|
const char *buf; |
|
int len; |
|
{ |
{ |
gz_stream *s = (gz_stream*)cookie; |
gz_stream *s = (gz_stream*)cookie; |
|
|
|
|
s->z_stream.avail_in = len; |
s->z_stream.avail_in = len; |
|
|
while (s->z_stream.avail_in != 0) { |
while (s->z_stream.avail_in != 0) { |
|
|
if (s->z_stream.avail_out == 0) { |
if (s->z_stream.avail_out == 0) { |
|
|
if (write(s->z_fd, s->z_buf, Z_BUFSIZE) != Z_BUFSIZE) |
if (write(s->z_fd, s->z_buf, Z_BUFSIZE) != Z_BUFSIZE) |
break; |
break; |
s->z_stream.next_out = s->z_buf; |
s->z_stream.next_out = s->z_buf; |