version 1.11, 2003/07/10 00:06:50 |
version 1.12, 2003/07/11 02:31:18 |
|
|
|
|
static int put_int32(gz_stream *, u_int32_t); |
static int put_int32(gz_stream *, u_int32_t); |
static u_int32_t get_int32(gz_stream *); |
static u_int32_t get_int32(gz_stream *); |
static int get_header(gz_stream *); |
static int get_header(gz_stream *, int); |
static int get_byte(gz_stream *); |
static int get_byte(gz_stream *); |
|
|
int |
|
gz_check_header(int fd, struct stat *sb, const char *ofn) |
|
{ |
|
int f; |
|
u_char buf[sizeof(gz_magic)]; |
|
off_t off = lseek(fd, 0, SEEK_CUR); |
|
|
|
f = (read(fd, buf, sizeof(buf)) == sizeof(buf) && |
|
!memcmp(buf, gz_magic, sizeof(buf))); |
|
|
|
lseek (fd, off, SEEK_SET); |
|
|
|
return f; |
|
} |
|
|
|
void * |
void * |
gz_open(int fd, const char *mode, int bits) |
gz_open(int fd, const char *mode, int bits, int gotmagic) |
{ |
{ |
gz_stream *s; |
gz_stream *s; |
|
|
|
|
s = NULL; |
s = NULL; |
} |
} |
} else { |
} else { |
if (get_header(s) != 0) { /* skip the .gz header */ |
if (get_header(s, gotmagic) != 0) { /* skip the .gz header */ |
gz_close (s); |
gz_close (s); |
s = NULL; |
s = NULL; |
} |
} |
|
|
} |
} |
|
|
static int |
static int |
get_header(gz_stream *s) |
get_header(gz_stream *s, int gotmagic) |
{ |
{ |
int method; /* method byte */ |
int method; /* method byte */ |
int flags; /* flags byte */ |
int flags; /* flags byte */ |
|
|
int c; |
int c; |
|
|
/* Check the gzip magic header */ |
/* Check the gzip magic header */ |
for (len = 0; len < 2; len++) { |
if (!gotmagic) { |
c = get_byte(s); |
for (len = 0; len < 2; len++) { |
if (c != gz_magic[len]) { |
c = get_byte(s); |
errno = EFTYPE; |
if (c != gz_magic[len]) { |
return -1; |
errno = EFTYPE; |
|
return -1; |
|
} |
} |
} |
} |
} |
|
|