#include <pwd.h>
#include <errno.h>
#include <dirent.h>
+#include <inttypes.h>
#include "zlib.h"
#include "util/crc32.h"
deflate_and_write_to_disk(const void *in_data, size_t in_data_size, int dest,
const char *filename)
{
- unsigned char out[BUFSIZE];
+ unsigned char *out;
/* allocate deflate state */
z_stream strm;
/* compress until end of in_data */
size_t compressed_size = 0;
int flush;
+
+ out = malloc(BUFSIZE * sizeof(unsigned char));
+ if (out == NULL)
+ return 0;
+
do {
int remaining = in_data_size - BUFSIZE;
flush = remaining > 0 ? Z_NO_FLUSH : Z_FINISH;
ssize_t written = write_all(dest, out, have);
if (written == -1) {
(void)deflateEnd(&strm);
+ free(out);
return 0;
}
} while (strm.avail_out == 0);
/* clean up and return */
(void)deflateEnd(&strm);
+ free(out);
return compressed_size;
}