Source
size_t zbx_json_addstring_limit( struct zbx_json *j, const char *name, const char *string, zbx_json_type_t type,
/*
** 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 Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/******************************************************************************
* *
* Purpose: return string describing json error *
* *
* Return value: pointer to the null terminated string *
* *
******************************************************************************/
static ZBX_THREAD_LOCAL char zbx_json_strerror_message[ZBX_JSON_MAX_STRERROR];
const char *zbx_json_strerror(void)
{
return zbx_json_strerror_message;
}
void zbx_set_json_strerror(const char *fmt, ...)
{
size_t sz;
va_list args;
va_start(args, fmt);
sz = zbx_vsnprintf(zbx_json_strerror_message, sizeof(zbx_json_strerror_message), fmt, args);
if (sizeof(zbx_json_strerror_message) - 1 == sz)
{
/* ensure that the string is not cut in the middle of UTF-8 sequence */
size_t idx = sz - 1;
while (0x80 == (0xc0 & zbx_json_strerror_message[idx]) && 0 < idx)
idx--;
if (zbx_utf8_char_len(zbx_json_strerror_message + idx) != sz - idx)
zbx_json_strerror_message[idx] = '\0';
}
va_end(args);
}
static void __zbx_json_realloc(struct zbx_json *j, size_t need)
{
int realloc = 0;