Source
xxxxxxxxxx
if (Z_OK != (zbx_zlib_errno = uncompress((Bytef *)out, &size_o, (const Bytef *)in, size_in)))
/*
** Zabbix
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
static int zbx_zlib_errno = 0;
/******************************************************************************
* *
* Purpose: returns last conversion error message *
* *
******************************************************************************/
const char *zbx_compress_strerror(void)
{
static char message[ZBX_COMPRESS_STRERROR_LEN];
switch (zbx_zlib_errno)
{
case Z_ERRNO:
zbx_strlcpy(message, zbx_strerror(errno), sizeof(message));
break;
case Z_MEM_ERROR:
zbx_strlcpy(message, "not enough memory", sizeof(message));
break;
case Z_BUF_ERROR:
zbx_strlcpy(message, "not enough space in output buffer", sizeof(message));
break;
case Z_DATA_ERROR:
zbx_strlcpy(message, "corrupted input data", sizeof(message));
break;
default:
zbx_snprintf(message, sizeof(message), "unknown error (%d)", zbx_zlib_errno);
break;
}
return message;
}
/******************************************************************************
* *
* Purpose: compress data *
* *
* Parameters: in - [IN] the data to compress *
* size_in - [IN] the input data size *
* out - [OUT] the compressed data *
* size_out - [OUT] the compressed data size *
* *
* Return value: SUCCEED - the data was compressed successfully *
* FAIL - otherwise *
* *
* Comments: In the case of success the output buffer must be freed by the *
* caller. *
* *
******************************************************************************/
int zbx_compress(const char *in, size_t size_in, char **out, size_t *size_out)
{
Bytef *buf;
uLongf buf_size;
buf_size = compressBound(size_in);
buf = (Bytef *)zbx_malloc(NULL, buf_size);
if (Z_OK != (zbx_zlib_errno = compress(buf, &buf_size, (const Bytef *)in, size_in)))
{
zbx_free(buf);
return FAIL;
}