27 # include <sys/types.h> 28 # include <sys/mman.h> 29 # include <sys/stat.h> 32 #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 35 # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 37 # define SET_BINARY_MODE(file) 41 # define unlink delete 42 # define GZ_SUFFIX "-gz" 45 # define unlink remove 46 # define GZ_SUFFIX "-gz" 47 # define fileno(file) file->__file 49 #if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os 54 extern int unlink
OF((
const char *));
58 # define GZ_SUFFIX ".gz" 60 #define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1) 63 #define MAX_NAME_LEN 1024 74 void error OF((
const char *msg));
77 int gz_compress_mmap
OF((FILE *in,
gzFile out));
82 int main OF((
int argc,
char *argv[]));
90 fprintf(stderr,
"%s: %s\n", prog, msg);
110 if (gz_compress_mmap(in, out) ==
Z_OK)
return;
113 len = (
int)fread(buf, 1,
sizeof(buf), in);
131 int gz_compress_mmap(in, out)
137 int ifd = fileno(in);
143 if (fstat(ifd, &sb) < 0)
return Z_ERRNO;
144 buf_len = sb.st_size;
145 if (buf_len <= 0)
return Z_ERRNO;
148 buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
149 if (buf == (caddr_t)(-1))
return Z_ERRNO;
152 len =
gzwrite(out, (
char *)buf, (
unsigned)buf_len);
156 munmap(buf, buf_len);
175 len =
gzread(in, buf,
sizeof(buf));
179 if ((
int)fwrite(buf, 1, (
unsigned)len, out) != len) {
180 error(
"failed fwrite");
183 if (fclose(out))
error(
"failed fclose");
201 strcpy(outfile, file);
204 in = fopen(file,
"rb");
209 out =
gzopen(outfile, mode);
211 fprintf(stderr,
"%s: can't gzopen %s\n", prog, outfile);
237 outfile[len-3] =
'\0';
243 in =
gzopen(infile,
"rb");
245 fprintf(stderr,
"%s: can't gzopen %s\n", prog, infile);
248 out = fopen(outfile,
"wb");
277 strcpy(outmode,
"wb6 ");
283 if (strcmp(*argv,
"-d") == 0)
285 else if (strcmp(*argv,
"-f") == 0)
287 else if (strcmp(*argv,
"-h") == 0)
289 else if (strcmp(*argv,
"-r") == 0)
291 else if ((*argv)[0] ==
'-' && (*argv)[1] >=
'1' && (*argv)[1] <=
'9' &&
293 outmode[2] = (*argv)[1];
298 if (outmode[3] ==
' ')
304 file =
gzdopen(fileno(stdin),
"rb");
305 if (file == NULL)
error(
"can't gzdopen stdin");
308 file =
gzdopen(fileno(stdout), outmode);
309 if (file == NULL)
error(
"can't gzdopen stdout");
319 }
while (argv++, --argc);
gzFile ZEXPORT gzdopen(int fd, const char *mode)
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
int unlink OF((const char *))
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
void error(char *msg) const
int ZEXPORT gzclose(gzFile file)
gzFile ZEXPORT gzopen(char *path, const char *mode) const
void file_compress(char *file, char *mode)
#define SET_BINARY_MODE(file)
const char *ZEXPORT gzerror(gzFile file, int *errnum)
void file_uncompress(char *file)
void gz_compress(FILE *in, gzFile out)
void gz_uncompress(gzFile in, FILE *out)