new upstream release (3.3.0); modify package compatibility for Stretch
[ossec-hids.git] / src / os_zlib / os_zlib.c
1 /* Copyright (C) 2009 Trend Micro Inc.
2  * All rights reserved.
3  *
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
7  * Foundation
8  */
9
10 #include "os_zlib.h"
11
12 #ifdef ZLIB_SYSTEM
13 #include <zlib.h>
14 #else
15 #include "../external/zlib-1.2.11/zlib.h"
16 #endif
17
18 unsigned long int os_zlib_compress(const char *src, char *dst,
19                                    unsigned long int src_size,
20                                    unsigned long int dst_size)
21 {
22     if (compress2((Bytef *)dst,
23                   &dst_size,
24                   (const Bytef *)src,
25                   src_size,
26                   Z_BEST_COMPRESSION) == Z_OK) {
27         dst[dst_size] = '\0';
28         return (dst_size);
29     }
30
31     return (0);
32 }
33
34 unsigned long int os_zlib_uncompress(const char *src, char *dst,
35                                      unsigned long int src_size,
36                                      unsigned long int dst_size)
37 {
38     if (uncompress((Bytef *)dst,
39                    &dst_size,
40                    (const Bytef *)src,
41                    src_size) == Z_OK) {
42         dst[dst_size] = '\0';
43         return (dst_size);
44     }
45
46     return (0);
47 }
48