1 /* Copyright (C) 2009 Trend Micro Inc.
4 * This program is a free software; you can redistribute it
5 * and/or modify it under the terms of the GNU General Public
6 * License (version 2) as published by the FSF - Free Software
16 #include "../external/zlib-1.2.11/zlib.h"
20 void OS_CompressLog(const char *logfile)
25 char logfileGZ[OS_FLSIZE + 1];
28 char buf[OS_MAXSTR + 1];
31 if (mond.compress == 0) {
36 memset(logfileGZ, '\0', OS_FLSIZE + 1);
37 memset(buf, '\0', OS_MAXSTR + 1);
42 /* Create the gzip file name */
43 snprintf(logfileGZ, OS_FLSIZE, "%s.gz", logfile);
46 log = fopen(logfile, "r");
48 /* Do not warn in here, since the alert file may not exist */
52 /* Open compressed file */
53 zlog = gzopen(logfileGZ, "w");
56 merror(FOPEN_ERROR, ARGV0, logfileGZ, errno, strerror(errno));
61 len = (int) fread(buf, 1, OS_MAXSTR, log);
65 if (gzwrite(zlog, buf, (unsigned)len) != len) {
66 merror("%s: Compression error: %s", ARGV0, gzerror(zlog, &err));
73 /* Remove uncompressed file */