Rizin
unix-like reverse engineering framework and cli tools
gun.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <utime.h>
#include "zlib.h"

Go to the source code of this file.

Classes

struct  ind
 
struct  outd
 

Macros

#define local   static
 
#define SIZE   32768U /* input and output buffer sizes */
 
#define PIECE   16384 /* limits i/o chunks for 16-bit int case */
 
#define NEXT()
 
#define FLUSHCODE()
 

Functions

unsigned in (void *in_desc, z_const unsigned char **buf)
 
int out (void *out_desc, unsigned char *buf, unsigned len)
 
int lunpipe (unsigned have, z_const unsigned char *next, struct ind *indp, int outfile, z_stream *strm)
 
int gunpipe (z_stream *strm, int infile, int outfile)
 
void copymeta (char *from, char *to)
 
int gunzip (z_stream *strm, char *inname, char *outname, int test)
 
int main (int argc, char **argv)
 

Variables

unsigned char inbuf [SIZE]
 
unsigned char outbuf [SIZE]
 
unsigned short prefix [65536]
 
unsigned char suffix [65536]
 
unsigned char match [65280+2]
 

Macro Definition Documentation

◆ FLUSHCODE

#define FLUSHCODE ( )
Value:
do { \
left = 0; \
rem = 0; \
if (chunk > have) { \
chunk -= have; \
have = 0; \
if (NEXT() == -1) \
break; \
chunk--; \
if (chunk > have) { \
chunk = have = 0; \
break; \
} \
} \
have -= chunk; \
next += chunk; \
chunk = 0; \
} while (0)
#define NEXT()
Definition: gun.c:155
Definition: malloc.c:21

Definition at line 171 of file gun.c.

◆ local

#define local   static

Definition at line 73 of file gun.c.

◆ NEXT

#define NEXT ( )
Value:
(have ? 0 : (have = in(indp, &next)), \
last = have ? (have--, (int)(*next++)) : -1)
unsigned in(void *in_desc, z_const unsigned char **buf)
Definition: gun.c:89

Definition at line 155 of file gun.c.

◆ PIECE

#define PIECE   16384 /* limits i/o chunks for 16-bit int case */

Definition at line 77 of file gun.c.

◆ SIZE

#define SIZE   32768U /* input and output buffer sizes */

Definition at line 76 of file gun.c.

Function Documentation

◆ copymeta()

void copymeta ( char *  from,
char *  to 
)

Definition at line 517 of file gun.c.

518 {
519  struct stat was;
520  struct utimbuf when;
521 
522  /* get all of from's Unix meta data, return if not a regular file */
523  if (stat(from, &was) != 0 || (was.st_mode & S_IFMT) != S_IFREG)
524  return;
525 
526  /* set to's mode bits, ignore errors */
527  (void)chmod(to, was.st_mode & 07777);
528 
529  /* copy owner's user and group, ignore errors */
530  (void)chown(to, was.st_uid, was.st_gid);
531 
532  /* copy access and modify times, ignore errors */
533  when.actime = was.st_atime;
534  when.modtime = was.st_mtime;
535  (void)utime(to, &when);
536 }
static static fork const void static count static fd const char const char static newpath const char static path chmod
Definition: sflib.h:35
when
Definition: fread.c:45
static stat
Definition: sflib.h:131
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds utime
Definition: sflib.h:57
static const char struct stat static buf struct stat static buf static vhangup int struct rusage static rusage struct sysinfo static info unsigned static __unused struct utsname static buf const char static size const char static name static pid unsigned static persona static fsgid const void static flags const struct iovec static count static fd const void static len static munlockall struct sched_param static p static sched_yield static policy const struct timespec struct timespec static rem uid_t uid_t uid_t static suid struct pollfd unsigned static timeout chown
Definition: sflib.h:210
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr from
Definition: sfsocketcall.h:123
static struct sockaddr static addrlen static backlog const void static flags void struct sockaddr socklen_t static fromlen const void const struct sockaddr to
Definition: sfsocketcall.h:125
Definition: sftypes.h:80

References chmod, chown, from, stat, to, and utime.

Referenced by gunzip().

◆ gunpipe()

int gunpipe ( z_stream strm,
int  infile,
int  outfile 
)

Definition at line 383 of file gun.c.

384 {
385  int ret, first, last;
386  unsigned have, flags, len;
387  z_const unsigned char *next = NULL;
388  struct ind ind, *indp;
389  struct outd outd;
390 
391  /* setup input buffer */
392  ind.infile = infile;
393  ind.inbuf = inbuf;
394  indp = &ind;
395 
396  /* decompress concatenated gzip streams */
397  have = 0; /* no input data read in yet */
398  first = 1; /* looking for first gzip header */
399  strm->next_in = Z_NULL; /* so Z_BUF_ERROR means EOF */
400  for (;;) {
401  /* look for the two magic header bytes for a gzip stream */
402  if (NEXT() == -1) {
403  ret = Z_OK;
404  break; /* empty gzip stream is ok */
405  }
406  if (last != 31 || (NEXT() != 139 && last != 157)) {
407  strm->msg = (char *)"incorrect header check";
408  ret = first ? Z_DATA_ERROR : Z_ERRNO;
409  break; /* not a gzip or compress header */
410  }
411  first = 0; /* next non-header is junk */
412 
413  /* process a compress (LZW) file -- can't be concatenated after this */
414  if (last == 157) {
415  ret = lunpipe(have, next, indp, outfile, strm);
416  break;
417  }
418 
419  /* process remainder of gzip header */
420  ret = Z_BUF_ERROR;
421  if (NEXT() != 8) { /* only deflate method allowed */
422  if (last == -1) break;
423  strm->msg = (char *)"unknown compression method";
424  ret = Z_DATA_ERROR;
425  break;
426  }
427  flags = NEXT(); /* header flags */
428  NEXT(); /* discard mod time, xflgs, os */
429  NEXT();
430  NEXT();
431  NEXT();
432  NEXT();
433  NEXT();
434  if (last == -1) break;
435  if (flags & 0xe0) {
436  strm->msg = (char *)"unknown header flags set";
437  ret = Z_DATA_ERROR;
438  break;
439  }
440  if (flags & 4) { /* extra field */
441  len = NEXT();
442  len += (unsigned)(NEXT()) << 8;
443  if (last == -1) break;
444  while (len > have) {
445  len -= have;
446  have = 0;
447  if (NEXT() == -1) break;
448  len--;
449  }
450  if (last == -1) break;
451  have -= len;
452  next += len;
453  }
454  if (flags & 8) /* file name */
455  while (NEXT() != 0 && last != -1)
456  ;
457  if (flags & 16) /* comment */
458  while (NEXT() != 0 && last != -1)
459  ;
460  if (flags & 2) { /* header crc */
461  NEXT();
462  NEXT();
463  }
464  if (last == -1) break;
465 
466  /* set up output */
467  outd.outfile = outfile;
468  outd.check = 1;
469  outd.crc = crc32(0L, Z_NULL, 0);
470  outd.total = 0;
471 
472  /* decompress data to output */
473  strm->next_in = next;
474  strm->avail_in = have;
475  ret = inflateBack(strm, in, indp, out, &outd);
476  if (ret != Z_STREAM_END) break;
477  next = strm->next_in;
478  have = strm->avail_in;
479  strm->next_in = Z_NULL; /* so Z_BUF_ERROR means EOF */
480 
481  /* check trailer */
482  ret = Z_BUF_ERROR;
483  if (NEXT() != (int)(outd.crc & 0xff) ||
484  NEXT() != (int)((outd.crc >> 8) & 0xff) ||
485  NEXT() != (int)((outd.crc >> 16) & 0xff) ||
486  NEXT() != (int)((outd.crc >> 24) & 0xff)) {
487  /* crc error */
488  if (last != -1) {
489  strm->msg = (char *)"incorrect data check";
490  ret = Z_DATA_ERROR;
491  }
492  break;
493  }
494  if (NEXT() != (int)(outd.total & 0xff) ||
495  NEXT() != (int)((outd.total >> 8) & 0xff) ||
496  NEXT() != (int)((outd.total >> 16) & 0xff) ||
497  NEXT() != (int)((outd.total >> 24) & 0xff)) {
498  /* length error */
499  if (last != -1) {
500  strm->msg = (char *)"incorrect length check";
501  ret = Z_DATA_ERROR;
502  }
503  break;
504  }
505 
506  /* go back and look for another gzip stream */
507  }
508 
509  /* clean up and return */
510  return ret;
511 }
size_t len
Definition: 6502dis.c:15
#define NULL
Definition: cris-opc.c:27
static lzma_stream strm
Definition: full_flush.c:20
FILE * outfile
Definition: fuzz_diff.c:16
int out(void *out_desc, unsigned char *buf, unsigned len)
Definition: gun.c:131
int lunpipe(unsigned have, z_const unsigned char *next, struct ind *indp, int outfile, z_stream *strm)
Definition: gun.c:200
unsigned char inbuf[SIZE]
Definition: gun.c:161
int ZEXPORT inflateBack(z_streamp strm, in_func in, void FAR *in_desc, out_func out, void FAR *out_desc)
Definition: infback.c:250
static void struct sockaddr socklen_t static fromlen static backlog static fork char char char static envp int struct rusage static rusage struct utsname static buf struct sembuf unsigned
Definition: sflib.h:97
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
static int
Definition: sfsocketcall.h:114
Definition: gun.c:81
unsigned char * inbuf
Definition: gun.c:83
int infile
Definition: gun.c:82
Definition: z80asm.h:95
const uint8_t * next_in
Definition: base.h:486
size_t avail_in
Definition: base.h:487
Definition: gun.c:119
unsigned long total
Definition: gun.c:123
int check
Definition: gun.c:121
int outfile
Definition: gun.c:120
unsigned long crc
Definition: gun.c:122
#define z_const
Definition: zconf.h:237
#define L
Definition: zip_err_str.c:7
unsigned long ZEXPORT crc32(unsigned long crc, const unsigned char FAR *buf, uInt len)
Definition: crc32.c:1063
#define Z_ERRNO
Definition: zlib.h:180
#define Z_BUF_ERROR
Definition: zlib.h:184
#define Z_STREAM_END
Definition: zlib.h:178
#define Z_OK
Definition: zlib.h:177
#define Z_DATA_ERROR
Definition: zlib.h:182
#define Z_NULL
Definition: zlib.h:212

References lzma_stream::avail_in, outd::check, outd::crc, crc32(), flags, in(), ind::inbuf, inbuf, ind::infile, inflateBack(), int, L, len, lunpipe(), NEXT, lzma_stream::next_in, NULL, out(), outfile, outd::outfile, strm, outd::total, unsigned, Z_BUF_ERROR, z_const, Z_DATA_ERROR, Z_ERRNO, Z_NULL, Z_OK, and Z_STREAM_END.

Referenced by gunzip().

◆ gunzip()

int gunzip ( z_stream strm,
char *  inname,
char *  outname,
int  test 
)

Definition at line 548 of file gun.c.

549 {
550  int ret;
551  int infile, outfile;
552 
553  /* open files */
554  if (inname == NULL || *inname == 0) {
555  inname = "-";
556  infile = 0; /* stdin */
557  }
558  else {
559  infile = open(inname, O_RDONLY, 0);
560  if (infile == -1) {
561  fprintf(stderr, "gun cannot open %s\n", inname);
562  return 0;
563  }
564  }
565  if (test)
566  outfile = -1;
567  else if (outname == NULL || *outname == 0) {
568  outname = "-";
569  outfile = 1; /* stdout */
570  }
571  else {
572  outfile = open(outname, O_CREAT | O_TRUNC | O_WRONLY, 0666);
573  if (outfile == -1) {
574  close(infile);
575  fprintf(stderr, "gun cannot create %s\n", outname);
576  return 0;
577  }
578  }
579  errno = 0;
580 
581  /* decompress */
582  ret = gunpipe(strm, infile, outfile);
583  if (outfile > 2) close(outfile);
584  if (infile > 2) close(infile);
585 
586  /* interpret result */
587  switch (ret) {
588  case Z_OK:
589  case Z_ERRNO:
590  if (infile > 2 && outfile > 2) {
591  copymeta(inname, outname); /* copy attributes */
592  unlink(inname);
593  }
594  if (ret == Z_ERRNO)
595  fprintf(stderr, "gun warning: trailing garbage ignored in %s\n",
596  inname);
597  break;
598  case Z_DATA_ERROR:
599  if (outfile > 2) unlink(outname);
600  fprintf(stderr, "gun data error on %s: %s\n", inname, strm->msg);
601  break;
602  case Z_MEM_ERROR:
603  if (outfile > 2) unlink(outname);
604  fprintf(stderr, "gun out of memory error--aborting\n");
605  return 1;
606  case Z_BUF_ERROR:
607  if (outfile > 2) unlink(outname);
608  if (strm->next_in != Z_NULL) {
609  fprintf(stderr, "gun write error on %s: %s\n",
610  outname, strerror(errno));
611  }
612  else if (errno) {
613  fprintf(stderr, "gun read error on %s: %s\n",
614  inname, strerror(errno));
615  }
616  else {
617  fprintf(stderr, "gun unexpected end of file on %s\n",
618  inname);
619  }
620  break;
621  default:
622  if (outfile > 2) unlink(outname);
623  fprintf(stderr, "gun internal error--aborting\n");
624  return 1;
625  }
626  return 0;
627 }
static static fork const void static count close
Definition: sflib.h:33
int gunpipe(z_stream *strm, int infile, int outfile)
Definition: gun.c:383
void copymeta(char *from, char *to)
Definition: gun.c:517
static static fork const void static count static fd const char static mode unlink
Definition: sflib.h:41
-lz4-versions
#define O_WRONLY
Definition: sftypes.h:487
#define O_CREAT
Definition: sftypes.h:489
#define O_RDONLY
Definition: sftypes.h:486
#define O_TRUNC
Definition: sftypes.h:492
#define Z_MEM_ERROR
Definition: zlib.h:183

References close, copymeta(), gunpipe(), lzma_stream::next_in, NULL, O_CREAT, O_RDONLY, O_TRUNC, O_WRONLY, outfile, strm, unlink, Z_BUF_ERROR, Z_DATA_ERROR, Z_ERRNO, Z_MEM_ERROR, Z_NULL, and Z_OK.

Referenced by main().

◆ in()

unsigned in ( void *  in_desc,
z_const unsigned char **  buf 
)

Definition at line 89 of file gun.c.

90 {
91  int ret;
92  unsigned len;
93  unsigned char *next;
94  struct ind *me = (struct ind *)in_desc;
95 
96  next = me->inbuf;
97  *buf = next;
98  len = 0;
99  do {
100  ret = PIECE;
101  if ((unsigned)ret > SIZE - len)
102  ret = (int)(SIZE - len);
103  ret = (int)read(me->infile, next, ret);
104  if (ret == -1) {
105  len = 0;
106  break;
107  }
108  next += ret;
109  len += ret;
110  } while (ret != 0 && len < SIZE);
111  return len;
112 }
#define SIZE
Definition: gun.c:76
#define PIECE
Definition: gun.c:77
voidpf void * buf
Definition: ioapi.h:138
int read(izstream &zs, T *x, Items items)
Definition: zstream.h:115

References ind::inbuf, ind::infile, int, len, PIECE, read(), and SIZE.

Referenced by gunpipe().

◆ lunpipe()

int lunpipe ( unsigned  have,
z_const unsigned char *  next,
struct ind indp,
int  outfile,
z_stream strm 
)

Definition at line 200 of file gun.c.

202 {
203  int last; /* last byte read by NEXT(), or -1 if EOF */
204  unsigned chunk; /* bytes left in current chunk */
205  int left; /* bits left in rem */
206  unsigned rem; /* unused bits from input */
207  int bits; /* current bits per code */
208  unsigned code; /* code, table traversal index */
209  unsigned mask; /* mask for current bits codes */
210  int max; /* maximum bits per code for this stream */
211  unsigned flags; /* compress flags, then block compress flag */
212  unsigned end; /* last valid entry in prefix/suffix tables */
213  unsigned temp; /* current code */
214  unsigned prev; /* previous code */
215  unsigned final; /* last character written for previous code */
216  unsigned stack; /* next position for reversed string */
217  unsigned outcnt; /* bytes in output buffer */
218  struct outd outd; /* output structure */
219  unsigned char *p;
220 
221  /* set up output */
222  outd.outfile = outfile;
223  outd.check = 0;
224 
225  /* process remainder of compress header -- a flags byte */
226  flags = NEXT();
227  if (last == -1)
228  return Z_BUF_ERROR;
229  if (flags & 0x60) {
230  strm->msg = (char *)"unknown lzw flags set";
231  return Z_DATA_ERROR;
232  }
233  max = flags & 0x1f;
234  if (max < 9 || max > 16) {
235  strm->msg = (char *)"lzw bits out of range";
236  return Z_DATA_ERROR;
237  }
238  if (max == 9) /* 9 doesn't really mean 9 */
239  max = 10;
240  flags &= 0x80; /* true if block compress */
241 
242  /* clear table */
243  bits = 9;
244  mask = 0x1ff;
245  end = flags ? 256 : 255;
246 
247  /* set up: get first 9-bit code, which is the first decompressed byte, but
248  don't create a table entry until the next code */
249  if (NEXT() == -1) /* no compressed data is ok */
250  return Z_OK;
251  final = prev = (unsigned)last; /* low 8 bits of code */
252  if (NEXT() == -1) /* missing a bit */
253  return Z_BUF_ERROR;
254  if (last & 1) { /* code must be < 256 */
255  strm->msg = (char *)"invalid lzw code";
256  return Z_DATA_ERROR;
257  }
258  rem = (unsigned)last >> 1; /* remaining 7 bits */
259  left = 7;
260  chunk = bits - 2; /* 7 bytes left in this chunk */
261  outbuf[0] = (unsigned char)final; /* write first decompressed byte */
262  outcnt = 1;
263 
264  /* decode codes */
265  stack = 0;
266  for (;;) {
267  /* if the table will be full after this, increment the code size */
268  if (end >= mask && bits < max) {
269  FLUSHCODE();
270  bits++;
271  mask <<= 1;
272  mask++;
273  }
274 
275  /* get a code of length bits */
276  if (chunk == 0) /* decrement chunk modulo bits */
277  chunk = bits;
278  code = rem; /* low bits of code */
279  if (NEXT() == -1) { /* EOF is end of compressed data */
280  /* write remaining buffered output */
281  if (outcnt && out(&outd, outbuf, outcnt)) {
282  strm->next_in = outbuf; /* signal write error */
283  return Z_BUF_ERROR;
284  }
285  return Z_OK;
286  }
287  code += (unsigned)last << left; /* middle (or high) bits of code */
288  left += 8;
289  chunk--;
290  if (bits > left) { /* need more bits */
291  if (NEXT() == -1) /* can't end in middle of code */
292  return Z_BUF_ERROR;
293  code += (unsigned)last << left; /* high bits of code */
294  left += 8;
295  chunk--;
296  }
297  code &= mask; /* mask to current code length */
298  left -= bits; /* number of unused bits */
299  rem = (unsigned)last >> (8 - left); /* unused bits from last byte */
300 
301  /* process clear code (256) */
302  if (code == 256 && flags) {
303  FLUSHCODE();
304  bits = 9; /* initialize bits and mask */
305  mask = 0x1ff;
306  end = 255; /* empty table */
307  continue; /* get next code */
308  }
309 
310  /* special code to reuse last match */
311  temp = code; /* save the current code */
312  if (code > end) {
313  /* Be picky on the allowed code here, and make sure that the code
314  we drop through (prev) will be a valid index so that random
315  input does not cause an exception. The code != end + 1 check is
316  empirically derived, and not checked in the original uncompress
317  code. If this ever causes a problem, that check could be safely
318  removed. Leaving this check in greatly improves gun's ability
319  to detect random or corrupted input after a compress header.
320  In any case, the prev > end check must be retained. */
321  if (code != end + 1 || prev > end) {
322  strm->msg = (char *)"invalid lzw code";
323  return Z_DATA_ERROR;
324  }
325  match[stack++] = (unsigned char)final;
326  code = prev;
327  }
328 
329  /* walk through linked list to generate output in reverse order */
330  p = match + stack;
331  while (code >= 256) {
332  *p++ = suffix[code];
333  code = prefix[code];
334  }
335  stack = p - match;
336  match[stack++] = (unsigned char)code;
337  final = code;
338 
339  /* link new table entry */
340  if (end < mask) {
341  end++;
342  prefix[end] = (unsigned short)prev;
343  suffix[end] = (unsigned char)final;
344  }
345 
346  /* set previous code for next iteration */
347  prev = temp;
348 
349  /* write output in forward order */
350  while (stack > SIZE - outcnt) {
351  while (outcnt < SIZE)
352  outbuf[outcnt++] = match[--stack];
353  if (out(&outd, outbuf, outcnt)) {
354  strm->next_in = outbuf; /* signal write error */
355  return Z_BUF_ERROR;
356  }
357  outcnt = 0;
358  }
359  p = match + stack;
360  do {
361  outbuf[outcnt++] = *--p;
362  } while (p > match);
363  stack = 0;
364 
365  /* loop for next code with final and prev as the last match, rem and
366  left provide the first 0..7 bits of the next code, end is the last
367  valid table entry */
368  }
369 }
#define mask()
int bits(struct state *s, int need)
Definition: blast.c:72
int max
Definition: enough.c:225
unsigned char suffix[65536]
Definition: gun.c:164
#define FLUSHCODE()
Definition: gun.c:171
unsigned char outbuf[SIZE]
Definition: gun.c:162
unsigned char match[65280+2]
Definition: gun.c:165
unsigned short prefix[65536]
Definition: gun.c:163
void * p
Definition: libc.cpp:67
const char * code
Definition: pal.c:98
Definition: inftree9.h:24
Definition: engine.c:71
Definition: z80asm.h:140
static struct stack stack[MAX_INCLUDE]
Definition: z80asm.c:92

References bits(), outd::check, code, test_evm::end, flags, FLUSHCODE, mask, match, max, NEXT, lzma_stream::next_in, out(), outbuf, outfile, outd::outfile, p, prefix, SIZE, stack, strm, suffix, unsigned, Z_BUF_ERROR, Z_DATA_ERROR, and Z_OK.

Referenced by gunpipe().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 631 of file gun.c.

632 {
633  int ret, len, test;
634  char *outname;
635  unsigned char *window;
636  z_stream strm;
637 
638  /* initialize inflateBack state for repeated use */
639  window = match; /* reuse LZW match buffer */
640  strm.zalloc = Z_NULL;
641  strm.zfree = Z_NULL;
642  strm.opaque = Z_NULL;
643  ret = inflateBackInit(&strm, 15, window);
644  if (ret != Z_OK) {
645  fprintf(stderr, "gun out of memory error--aborting\n");
646  return 1;
647  }
648 
649  /* decompress each file to the same name with the suffix removed */
650  argc--;
651  argv++;
652  test = 0;
653  if (argc && strcmp(*argv, "-h") == 0) {
654  fprintf(stderr, "gun 1.6 (17 Jan 2010)\n");
655  fprintf(stderr, "Copyright (C) 2003-2010 Mark Adler\n");
656  fprintf(stderr, "usage: gun [-t] [file1.gz [file2.Z ...]]\n");
657  return 0;
658  }
659  if (argc && strcmp(*argv, "-t") == 0) {
660  test = 1;
661  argc--;
662  argv++;
663  }
664  if (argc)
665  do {
666  if (test)
667  outname = NULL;
668  else {
669  len = (int)strlen(*argv);
670  if (strcmp(*argv + len - 3, ".gz") == 0 ||
671  strcmp(*argv + len - 3, "-gz") == 0)
672  len -= 3;
673  else if (strcmp(*argv + len - 2, ".z") == 0 ||
674  strcmp(*argv + len - 2, "-z") == 0 ||
675  strcmp(*argv + len - 2, "_z") == 0 ||
676  strcmp(*argv + len - 2, ".Z") == 0)
677  len -= 2;
678  else {
679  fprintf(stderr, "gun error: no gz type on %s--skipping\n",
680  *argv);
681  continue;
682  }
683  outname = malloc(len + 1);
684  if (outname == NULL) {
685  fprintf(stderr, "gun out of memory error--aborting\n");
686  ret = 1;
687  break;
688  }
689  memcpy(outname, *argv, len);
690  outname[len] = 0;
691  }
692  ret = gunzip(&strm, *argv, outname, test);
693  if (outname != NULL) free(outname);
694  if (ret) break;
695  } while (argv++, --argc);
696  else
697  ret = gunzip(&strm, NULL, NULL, test);
698 
699  /* clean up */
701  return ret;
702 }
int gunzip(z_stream *strm, char *inname, char *outname, int test)
Definition: gun.c:548
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
int ZEXPORT inflateBackEnd(z_streamp strm)
Definition: infback.c:632
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * malloc(size_t size)
Definition: malloc.c:123
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
struct _window window
#define inflateBackInit(strm, windowBits, window)
Definition: zlib.h:1820

References argv, free(), gunzip(), inflateBackEnd(), inflateBackInit, int, len, malloc(), match, memcpy(), NULL, strm, test_customized_mnem::test(), Z_NULL, and Z_OK.

◆ out()

int out ( void *  out_desc,
unsigned char *  buf,
unsigned  len 
)

Definition at line 131 of file gun.c.

132 {
133  int ret;
134  struct outd *me = (struct outd *)out_desc;
135 
136  if (me->check) {
137  me->crc = crc32(me->crc, buf, len);
138  me->total += len;
139  }
140  if (me->outfile != -1)
141  do {
142  ret = PIECE;
143  if ((unsigned)ret > len)
144  ret = (int)len;
145  ret = (int)write(me->outfile, buf, ret);
146  if (ret == -1)
147  return 1;
148  buf += ret;
149  len -= ret;
150  } while (len != 0);
151  return 0;
152 }
static static fork write
Definition: sflib.h:33

References outd::check, outd::crc, crc32(), int, len, outd::outfile, PIECE, outd::total, and write.

Referenced by gunpipe(), and lunpipe().

Variable Documentation

◆ inbuf

◆ match

◆ outbuf

◆ prefix

◆ suffix