23 #if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__) 26 # define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY) 28 # define SET_BINARY_MODE(file) 51 return m > size ? m : (size_t)(-1);
70 in = name == NULL ? stdin : fopen(name,
"rb");
73 *len += fread((
char *)buf + *len, 1, size - *len, in);
74 if (*len < size)
break;
76 if (size == *len || (swap = realloc(buf, size)) == NULL) {
88 int main(
int argc,
char **argv)
90 int ret, put = 0, fail = 0;
92 char *arg, *name = NULL;
93 unsigned char *source = NULL, *dest;
95 unsigned long sourcelen, destlen;
98 while (arg = *++argv, --argc)
100 if (arg[1] ==
'w' && arg[2] == 0)
102 else if (arg[1] ==
'f' && arg[2] == 0)
104 else if (arg[1] >=
'0' && arg[1] <=
'9')
105 skip = (unsigned)atoi(arg + 1);
107 fprintf(stderr,
"invalid option %s\n", arg);
111 else if (name != NULL) {
112 fprintf(stderr,
"only one file name allowed\n");
117 source =
load(name, &len);
118 if (source == NULL) {
119 fprintf(stderr,
"memory allocation failure\n");
123 fprintf(stderr,
"could not read %s, or it was empty\n",
124 name == NULL ?
"<stdin>" : name);
129 fprintf(stderr,
"skip request of %d leaves no input\n", skip);
136 sourcelen = (
unsigned long)len;
137 ret =
puff(
NIL, &destlen, source + skip, &sourcelen);
139 fprintf(stderr,
"puff() failed with return code %d\n", ret);
141 fprintf(stderr,
"puff() succeeded uncompressing %lu bytes\n", destlen);
142 if (sourcelen < len) fprintf(stderr,
"%lu compressed bytes unused\n",
147 if (put && ret == 0) {
152 fprintf(stderr,
"memory allocation failure\n");
156 puff(dest, &destlen, source + skip, &sourcelen);
158 fwrite(dest, 1, destlen, stdout);
static size_t bythirds(size_t size)
int puff(unsigned char *dest, unsigned long *destlen, const unsigned char *source, unsigned long *sourcelen)
static void skip(file *in, unsigned n)
int main(int argc, char **argv)
#define SET_BINARY_MODE(file)
void swap(Array< D, S > &x, Array< D, S > &y)
static unsigned in(void *in_desc, z_const unsigned char **buf)
static void * load(const char *name, size_t *len)