#include <config.h>
#ifndef HAVE_SIG2STR
#include <sys/types.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#include <signal.h>
#include <unistd.h>
#include "sudo_compat.h"
#if defined(HAVE_DECL_SYS_SIGNAME) && HAVE_DECL_SYS_SIGNAME == 1
# define sudo_sys_signame sys_signame
#elif defined(HAVE_DECL__SYS_SIGNAME) && HAVE_DECL__SYS_SIGNAME == 1
# define sudo_sys_signame _sys_signame
#elif defined(HAVE_DECL_SYS_SIGABBREV) && HAVE_DECL_SYS_SIGABBREV == 1
# define sudo_sys_signame sys_sigabbrev
#else
# ifdef HAVE_SYS_SIGABBREV
# define sudo_sys_signame sys_sigabbrev
# endif
extern const char *const sudo_sys_signame[NSIG];
#endif
int
sudo_sig2str(int signo, char *signame)
{
#if defined(SIGRTMIN) && defined(SIGRTMAX)
if (signo >= SIGRTMIN && signo <= SIGRTMAX) {
snprintf(signame, SIG2STR_MAX, "RTMIN+%d", (signo - SIGRTMIN));
return 0;
}
#endif
if (signo > 0 && signo < NSIG && sudo_sys_signame[signo] != NULL) {
strlcpy(signame, sudo_sys_signame[signo], SIG2STR_MAX);
return 0;
}
errno = EINVAL;
return -1;
}
#endif