Source
/*
** Zabbix
** Copyright (C) 2001-2023 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.
**/
/* this file is for the minimal possible set of string related functions that are used by libzbxcommon.a */
/* or libraries/files it depends on */
/******************************************************************************
* *
* Purpose: Secure version of vsnprintf function. *
* Add zero character at the end of string. *
* *
* Parameters: str - [IN/OUT] destination buffer pointer *
* count - [IN] size of destination buffer *
* fmt - [IN] format *
* *
* Return value: the number of characters in the output buffer *
* (not including the trailing '\0') *
* *
******************************************************************************/
size_t zbx_vsnprintf(char *str, size_t count, const char *fmt, va_list args)
{
int written_len = 0;
if (0 < count)
{
if (0 > (written_len = vsnprintf(str, count, fmt, args)))
written_len = (int)count - 1; /* count an output error as a full buffer */
else
written_len = MIN(written_len, (int)count - 1); /* result could be truncated */
}
str[written_len] = '\0'; /* always write '\0', even if buffer size is 0 or vsnprintf() error */
return (size_t)written_len;
}
/******************************************************************************
* *
* Purpose: dynamical formatted output conversion *
* *
* Return value: formatted string *
* *
* Comments: returns a pointer to allocated memory *
* *
******************************************************************************/
char *zbx_dvsprintf(char *dest, const char *f, va_list args)