Go to the documentation of this file.
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__)
38 # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
40 # define SET_BINARY_MODE(file)
43 #if defined(_MSC_VER) && _MSC_VER < 1900
44 # define snprintf _snprintf
48 # define unlink delete
49 # define GZ_SUFFIX "-gz"
52 # define unlink remove
53 # define GZ_SUFFIX "-gz"
54 # define fileno(file) file->__file
56 #if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
60 #if !defined(Z_HAVE_UNISTD_H) && !defined(_LARGEFILE64_SOURCE)
62 extern int unlink OF((
const char *));
68 # define perror(s) pwinerror(s)
80 static char *strwinerror (
error)
83 static char buf[1024];
86 DWORD lasterr = GetLastError();
87 DWORD chars = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
88 | FORMAT_MESSAGE_ALLOCATE_BUFFER,
98 && msgbuf[chars - 2] ==
'\r' && msgbuf[chars - 1] ==
'\n') {
103 if (chars >
sizeof (
buf) - 1) {
104 chars =
sizeof (
buf) - 1;
108 wcstombs(
buf, msgbuf, chars + 1);
112 sprintf(
buf,
"unknown win32 error (%ld)",
error);
115 SetLastError(lasterr);
119 static void pwinerror (s)
123 fprintf(
stderr,
"%s: %s\n", s, strwinerror(GetLastError ()));
125 fprintf(
stderr,
"%s\n", strwinerror(GetLastError ()));
131 # define GZ_SUFFIX ".gz"
133 #define SUFFIX_LEN (sizeof(GZ_SUFFIX)-1)
136 #define MAX_NAME_LEN 1024
139 # define local static
148 #if defined(Z_HAVE_UNISTD_H) || defined(Z_LARGE)
152 void *myalloc
OF((
void *,
unsigned,
unsigned));
153 void myfree
OF((
void *,
void *));
155 void *myalloc(q,
n,
m)
204 gz = malloc(
sizeof(
struct gzFile_s));
207 gz->write = strchr(
mode,
'w') != NULL;
208 gz->strm.zalloc = myalloc;
209 gz->strm.zfree = myfree;
214 gz->strm.next_in = 0;
215 gz->strm.avail_in =
Z_NULL;
222 gz->file =
path == NULL ? fdopen(fd, gz->write ?
"wb" :
"rb") :
224 if (gz->file == NULL) {
244 if (gz == NULL || !gz->write)
270 if (gz == NULL || gz->write)
278 got = fread(
in, 1, 1, gz->file);
346 int main OF((
int argc,
char *argv[]));
374 if (gz_compress_mmap(
in,
out) ==
Z_OK)
return;
395 int gz_compress_mmap(
in,
out)
401 int ifd = fileno(
in);
407 if (fstat(ifd, &sb) < 0)
return Z_ERRNO;
408 buf_len = sb.st_size;
409 if (buf_len <= 0)
return Z_ERRNO;
412 buf = mmap((caddr_t) 0, buf_len, PROT_READ, MAP_SHARED, ifd, (off_t)0);
420 munmap(
buf, buf_len);
444 error(
"failed fwrite");
466 fprintf(
stderr,
"%s: filename too long\n",
prog);
470 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
506 fprintf(
stderr,
"%s: filename too long\n",
prog);
510 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
523 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
531 fprintf(
stderr,
"%s: can't gzopen %s\n",
prog, infile);
563 char *bname, outmode[20];
565 #if !defined(NO_snprintf) && !defined(NO_vsnprintf)
566 snprintf(outmode,
sizeof(outmode),
"%s",
"wb6 ");
568 strcpy(outmode,
"wb6 ");
572 bname = strrchr(argv[0],
'/');
579 if (!strcmp(bname,
"gunzip"))
581 else if (!strcmp(bname,
"zcat"))
582 copyout = uncompr = 1;
585 if (strcmp(*argv,
"-c") == 0)
587 else if (strcmp(*argv,
"-d") == 0)
589 else if (strcmp(*argv,
"-f") == 0)
591 else if (strcmp(*argv,
"-h") == 0)
593 else if (strcmp(*argv,
"-r") == 0)
595 else if ((*argv)[0] ==
'-' && (*argv)[1] >=
'1' && (*argv)[1] <=
'9' &&
597 outmode[2] = (*argv)[1];
602 if (outmode[3] ==
' ')
609 if (
file == NULL)
error(
"can't gzdopen stdin");
613 if (
file == NULL)
error(
"can't gzdopen stdout");
625 fprintf(
stderr,
"%s: can't gzopen %s\n",
prog, *argv);
633 FILE *
in = fopen(*argv,
"rb");
639 if (
file == NULL)
error(
"can't gzdopen stdout");
648 }
while (argv++, --argc);
int ZEXPORT inflateEnd(z_streamp strm)
int ZEXPORT inflate(z_streamp strm, int flush)
const grpc_generator::File * file
#define SET_BINARY_MODE(file)
const char *ZEXPORT gzerror(gzFile file, int *errnum)
int ZEXPORT gzwrite(gzFile file, voidpc buf, unsigned len)
void file_compress(char *file, char *mode)
int ZEXPORT deflateEnd(z_streamp strm)
void gz_uncompress(gzFile in, FILE *out)
void gz_compress(FILE *in, gzFile out)
int ZEXPORT inflateReset(z_streamp strm)
UniquePtr< SSL_SESSION > ret
int ZEXPORT deflate(z_streamp strm, int flush)
void file_uncompress(char *file)
gzFile ZEXPORT gzopen(char *path, const char *mode) const
int unlink OF((const char *))
gzFile ZEXPORT gzdopen(int fd, const char *mode)
gzFile gz_open(void *path, int fd, const char *mode) const
int ZEXPORT gzclose(gzFile file)
#define deflateInit2(strm, level, method, windowBits, memLevel, strategy)
int ZEXPORT gzread(gzFile file, voidp buf, unsigned len)
#define inflateInit2(strm, windowBits)
void error(char *msg) const
grpc
Author(s):
autogenerated on Fri May 16 2025 02:59:29