Imported Upstream version 2.7
[ossec-hids.git] / src / os_zlib / os_zlib.c
1 /* @(#) $Id: ./src/os_zlib/os_zlib.c, 2011/09/08 dcid Exp $
2  */
3
4 /* Copyright (C) 2009 Trend Micro Inc.
5  * All rights reserved.
6  *
7  * This program is a free software; you can redistribute it
8  * and/or modify it under the terms of the GNU General Public
9  * License (version 2) as published by the FSF - Free Software
10  * Foundation
11  */
12
13 #include "shared.h"
14 #include "os_zlib.h"
15
16 /* os_compress: Compress a string with zlib. */
17 int os_compress(char *src, char *dst, int src_size, int dst_size)
18 {
19     unsigned long int zl_dst = dst_size;
20
21     /* We make sure to do not allow long sizes */
22     if(compress2((unsigned char *)dst,
23                  &zl_dst,
24                  (unsigned char *)src,
25                  (unsigned long int)src_size, 9) == Z_OK)
26     {
27         dst[zl_dst] = '\0';
28         return(zl_dst);
29     }
30
31     return(0);
32 }
33
34
35 /* os_uncompress: Uncompress a string with zlib. */
36 int os_uncompress(char *src, char *dst, int src_size, int dst_size)
37 {
38     unsigned long int zl_dst = dst_size;
39
40     if(uncompress((unsigned char *)dst,
41                   &zl_dst,
42                   (unsigned char *)src,
43                   (unsigned long int)src_size) == Z_OK)
44     {
45         dst[zl_dst] = '\0';
46         return(zl_dst);
47     }
48     return(0);
49 }
50
51
52 /* EOF */