-
-struct myfile {
- int fd;
- unsigned long chars;
- unsigned char buffer[8192];
-};
-
-static FILE *create_file(const char *suffix)
-{
- static char filename[PATH_MAX];
- unsigned len;
-
- len = snprintf(filename, PATH_MAX, "%s.%s", base_name, suffix);
- if (len >= PATH_MAX)
- die("you wascally wabbit, you");
- return fopen(filename, "w");
-}
-
-static unsigned long fwrite_compressed(void *in, unsigned long size, FILE *f)
-{
- z_stream stream;
- unsigned long maxsize;
- void *out;
-
- memset(&stream, 0, sizeof(stream));
- deflateInit(&stream, Z_DEFAULT_COMPRESSION);
- maxsize = deflateBound(&stream, size);
- out = xmalloc(maxsize);
-
- /* Compress it */
- stream.next_in = in;
- stream.avail_in = size;
-
- stream.next_out = out;
- stream.avail_out = maxsize;
-
- while (deflate(&stream, Z_FINISH) == Z_OK)
- /* nothing */;
- deflateEnd(&stream);
-
- size = stream.total_out;
- fwrite(out, size, 1, f);
- free(out);
- return size;
-}