Source
/* log [file, <regexp>,<encoding>,<maxlines>, <mode>,<output>,<maxdelay>, <options>,<persistent_dir>] 9 params */
/*
** 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.
**/
/* ssize_t */
/* _WINDOWS */
/* maximum size of the first and the last blocks of the file to calculate MD5 sum for */
/* cannot compare file device and inode numbers */
/* both files have different device or inode numbers */
/* both files have the same device and inode numbers */
extern int CONFIG_MAX_LINES_PER_SECOND;
extern ZBX_THREAD_LOCAL char *CONFIG_HOSTNAME;
/******************************************************************************
* *
* Purpose: separates given string to two parts by given delimiter in string *
* *
* Parameters: *
* str - [IN] a not-empty string to split *
* del - [IN] pointer to a character in the string *
* part1 - [OUT] pointer to buffer for the first part with delimiter *
* part2 - [OUT] pointer to buffer for the second part *
* *
* Return value: SUCCEED - on splitting without errors *
* FAIL - on splitting with errors *
* *
* Comments: Memory for "part1" and "part2" is allocated only on SUCCEED. *
* *
******************************************************************************/
static int split_string(const char *str, const char *del, char **part1, char **part2)
{
size_t str_length, part1_length, part2_length;
int ret = FAIL;
zabbix_log(LOG_LEVEL_DEBUG, "In %s() str:'%s' del:'%s'", __func__, str, del);
str_length = strlen(str);
/* since the purpose of this function is to be used in split_filename(), we allow part1 to be */
/* just *del (e.g., "/" - file system root), but we do not allow part2 (filename) to be empty */
if (del < str || del >= (str + str_length - 1))
{
zabbix_log(LOG_LEVEL_DEBUG, "%s() cannot proceed: delimiter is out of range", __func__);
goto out;
}
part1_length = (size_t)(del - str + 1);
part2_length = str_length - part1_length;
*part1 = (char *)zbx_malloc(*part1, part1_length + 1);
zbx_strlcpy(*part1, str, part1_length + 1);