version 1.32, 2003/07/08 00:30:12 |
version 1.33, 2003/07/11 02:31:18 |
|
|
const struct compressor { |
const struct compressor { |
char *name; |
char *name; |
char *suffix; |
char *suffix; |
int (*check_header)(int, struct stat *, const char *); |
u_char *magic; |
void *(*open)(int, const char *, int); |
void *(*open)(int, const char *, int, int); |
int (*read)(void *, char *, int); |
int (*read)(void *, char *, int); |
int (*write)(void *, const char *, int); |
int (*write)(void *, const char *, int); |
int (*close)(void *); |
int (*close)(void *); |
} c_table[] = { |
} c_table[] = { |
#define M_COMPRESS (&c_table[0]) |
#define M_COMPRESS (&c_table[0]) |
{ "compress", ".Z", z_check_header, z_open, zread, zwrite, zclose }, |
{ "compress", ".Z", "\037\235", z_open, zread, zwrite, zclose }, |
#define M_DEFLATE (&c_table[1]) |
#define M_DEFLATE (&c_table[1]) |
{ "deflate", ".gz", gz_check_header, gz_open, gz_read, gz_write, gz_close }, |
{ "deflate", ".gz", "\037\213", gz_open, gz_read, gz_write, gz_close }, |
#if 0 |
#if 0 |
#define M_LZH (&c_table[2]) |
#define M_LZH (&c_table[2]) |
{ "lzh", ".lzh", lzh_check_header, lzh_open, lzh_read, lzh_write, lzh_close }, |
{ "lzh", ".lzh", "\037\240", lzh_open, lzh_read, lzh_write, lzh_close }, |
#define M_ZIP (&c_table[3]) |
#define M_ZIP (&c_table[3]) |
{ "zip", ".zip", zip_check_header, zip_open, zip_read, zip_write, zip_close }, |
{ "zip", ".zip", "PK", zip_open, zip_read, zip_write, zip_close }, |
#define M_PACK (&c_table[4]) |
#define M_PACK (&c_table[4]) |
{ "pack", ".pak",pak_check_header, pak_open, pak_read, pak_write, pak_close }, |
{ "pack", ".pak", "\037\036", pak_open, pak_read, pak_write, pak_close }, |
#endif |
#endif |
{ NULL } |
{ NULL } |
}; |
}; |
|
|
return (-1); |
return (-1); |
} |
} |
|
|
if ((cookie = (*method->open)(ofd, "w", bits)) == NULL) { |
if ((cookie = (*method->open)(ofd, "w", bits, 0)) == NULL) { |
if (verbose >= 0) |
if (verbose >= 0) |
warn("%s", in); |
warn("%s", in); |
(void) close(ofd); |
(void) close(ofd); |
|
|
check_method(int fd, struct stat *sb, const char *out) |
check_method(int fd, struct stat *sb, const char *out) |
{ |
{ |
const struct compressor *method; |
const struct compressor *method; |
|
u_char magic[2]; |
|
|
for (method = &c_table[0]; |
if (read(fd, magic, sizeof(magic)) != 2) |
method->name != NULL && !(*method->check_header)(fd, sb, out); |
return (NULL); |
method++) |
for (method = &c_table[0]; method->name != NULL; method++) { |
; |
if (magic[0] == method->magic[0] && |
|
magic[1] == method->magic[1]) |
if (method->name == NULL) |
return (method); |
method = NULL; |
} |
|
return (NULL); |
return (method); |
|
} |
} |
|
|
int |
int |
|
|
return -1; |
return -1; |
} |
} |
|
|
if (!pipin && (method = check_method(ifd, sb, out)) == NULL) { |
if ((method = check_method(ifd, sb, out)) == NULL) { |
if (verbose >= 0) |
if (verbose >= 0) |
warnx("%s: unrecognized file format", in); |
warnx("%s: unrecognized file format", in); |
close (ifd); |
close (ifd); |
return -1; |
return -1; |
} |
} |
|
|
if ((cookie = (*method->open)(ifd, "r", bits)) == NULL) { |
if ((cookie = (*method->open)(ifd, "r", bits, 1)) == NULL) { |
if (verbose >= 0) |
if (verbose >= 0) |
warn("%s", in); |
warn("%s", in); |
error++; |
error++; |