Source
/*
** 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/>.
**/
static ZBX_THREAD_LOCAL volatile sig_atomic_t zbx_timed_out; /* 0 - no timeout occurred, 1 - SIGALRM took place */
int __zbx_stat(const char *path, zbx_stat_t *buf)
{
int ret, fd;
wchar_t *wpath;
wpath = zbx_utf8_to_unicode(path);
if (-1 == (ret = _wstat64(wpath, buf)))
goto out;
if (0 != S_ISDIR(buf->st_mode) || 0 != buf->st_size)
goto out;
/* In the case of symlinks _wstat64 returns zero file size. */
/* Try to work around it by opening the file and using fstat. */
ret = -1;
if (-1 != (fd = _wopen(wpath, O_RDONLY)))
{
ret = _fstat64(fd, buf);
_close(fd);
}
out:
zbx_free(wpath);
return ret;
}
/******************************************************************************
* *
* Purpose: return program name without path *
* *
* Return value: program name without path *
* *
******************************************************************************/
const char *get_program_name(const char *path)
{
const char *filename = NULL;