/*
* Copyright (C) 2002-2010 Mark Adler
* For conditions of distribution and use, see copyright notice in puff.h
* version 2.2, 25 Apr 2010
*/
/* Example of how to use puff().
Usage: puff [-w] [-f] [-nnn] file
... | puff [-w] [-f] [-nnn]
where file is the input file with deflate data, nnn is the number of bytes
of input to skip before inflating (e.g. to skip a zlib or gzip header), and
-w is used to write the decompressed data to stdout. -f is for coverage
testing, and causes pufftest to fail with not enough output space (-f does
a write like -w, so -w is not required). */
#include <stdio.h>
#include <stdlib.h>
#include "puff.h"
# include <fcntl.h>
# include <io.h>
#else
#endif
#define local static
/* Return size times approximately the cube root of 2, keeping the result as 1,
3, or 5 times a power of 2 -- the result is always > size, until the result
is the maximum value of an unsigned long, where it remains. This is useful
to keep reallocations less than ~33% over the actual data. */
{
int n;
size_t m;
m = size;
for (n = 0; m; n++)
m >>= 1;
if (n < 3)
return size + 1;
n -= 3;
m = size >> n;
m += m == 6 ? 2 : 1;
m <<= n;
}
/* Read the input file *name, or stdin if name is NULL, into allocated memory.
Reallocate to larger buffers until the entire file is read in. Return a
pointer to the allocated data, or NULL if there was a memory allocation
failure. *len is the number of bytes of data read from the input file (even
if load() returns NULL). If the input file was empty or could not be opened
or read, *len is zero. */
{
*len = 0;
return NULL;
for (;;) {
break;
}
}
}
return buf;
}
{
unsigned skip = 0;
/* process arguments */
if (arg[0] == '-') {
put = 1;
else {
return 3;
}
}
return 3;
}
else
return 4;
}
if (len == 0) {
return 3;
}
return 3;
}
/* test inflate data with offset skip */
if (ret)
else {
}
/* if requested, inflate again and write decompressd data to stdout */
if (fail)
destlen >>= 1;
return 4;
}
}
/* clean up */
return ret;
}