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