2018-09-18 03:55:33 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* libs/libc/string/lib_strsignal.c
|
|
|
|
*
|
2021-03-02 22:54:21 +08:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2018-09-18 03:55:33 +08:00
|
|
|
*
|
2021-03-02 22:54:21 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-09-18 03:55:33 +08:00
|
|
|
*
|
2021-03-02 22:54:21 +08:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-09-18 03:55:33 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-03-21 22:56:51 +08:00
|
|
|
#include <errno.h>
|
2018-09-18 03:55:33 +08:00
|
|
|
#include <signal.h>
|
2023-03-21 22:56:51 +08:00
|
|
|
#include <stdio.h>
|
2018-09-18 03:55:33 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
2023-03-21 22:56:51 +08:00
|
|
|
* Pre-processor Definitions
|
2018-09-18 03:55:33 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
2023-03-21 22:56:51 +08:00
|
|
|
#ifdef CONFIG_LIBC_STRSIGNAL_SHORT
|
|
|
|
# define CASE_SIG_STR(sig, msg) \
|
|
|
|
case (sig): \
|
|
|
|
return (FAR char *)#sig
|
|
|
|
#else
|
|
|
|
# define CASE_SIG_STR(sig, msg) \
|
|
|
|
case (sig): \
|
|
|
|
return (FAR char *)(msg)
|
|
|
|
#endif
|
2018-09-18 03:55:33 +08:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2020-10-25 12:23:37 +08:00
|
|
|
* Name: strsignal
|
2018-09-18 03:55:33 +08:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The strsignal() function will map the signal number in signum to an
|
|
|
|
* implementation-defined string and will return a pointer to it.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR char *strsignal(int signum)
|
|
|
|
{
|
2023-03-21 22:56:51 +08:00
|
|
|
static char sigstr[32];
|
|
|
|
|
2018-09-18 03:55:33 +08:00
|
|
|
/* Handle invalid signals */
|
|
|
|
|
|
|
|
if (!GOOD_SIGNO(signum))
|
|
|
|
{
|
|
|
|
return (FAR char *)"Invalid Signal";
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle named signals */
|
|
|
|
|
|
|
|
switch (signum)
|
|
|
|
{
|
2023-03-21 22:56:51 +08:00
|
|
|
#ifdef CONFIG_LIBC_STRSIGNAL
|
2018-09-18 03:55:33 +08:00
|
|
|
/* Standard signals */
|
|
|
|
|
2023-03-21 22:56:51 +08:00
|
|
|
CASE_SIG_STR(SIGHUP, "Hangup");
|
|
|
|
CASE_SIG_STR(SIGINT, "Interrupt");
|
|
|
|
CASE_SIG_STR(SIGQUIT, "Quit");
|
|
|
|
CASE_SIG_STR(SIGILL, "Illegal instruction");
|
|
|
|
CASE_SIG_STR(SIGTRAP, "Trace/breakpoint trap");
|
|
|
|
CASE_SIG_STR(SIGABRT, "Aborted");
|
|
|
|
CASE_SIG_STR(SIGBUS, "Bus error");
|
|
|
|
CASE_SIG_STR(SIGFPE, "Arithmetic exception");
|
|
|
|
CASE_SIG_STR(SIGKILL, "Killed");
|
|
|
|
CASE_SIG_STR(SIGUSR1, "User defined signal 1");
|
|
|
|
CASE_SIG_STR(SIGSEGV, "Invalid memory reference");
|
|
|
|
CASE_SIG_STR(SIGUSR2, "User defined signal 2");
|
|
|
|
CASE_SIG_STR(SIGPIPE, "Broken pipe");
|
|
|
|
CASE_SIG_STR(SIGALRM, "Alarm clock");
|
|
|
|
CASE_SIG_STR(SIGTERM, "Terminated");
|
|
|
|
CASE_SIG_STR(SIGCHLD, "Child status changed");
|
|
|
|
CASE_SIG_STR(SIGCONT, "Continued");
|
|
|
|
CASE_SIG_STR(SIGSTOP, "Stopped (signal)");
|
|
|
|
CASE_SIG_STR(SIGTSTP, "Stopped");
|
|
|
|
CASE_SIG_STR(SIGTTIN, "Stopped (tty input)");
|
|
|
|
CASE_SIG_STR(SIGTTOU, "Stopped (tty output)");
|
|
|
|
CASE_SIG_STR(SIGURG, "Urgent I/O condition");
|
|
|
|
CASE_SIG_STR(SIGXCPU, "CPU time limit exceeded");
|
|
|
|
CASE_SIG_STR(SIGXFSZ, "File size limit exceeded");
|
|
|
|
CASE_SIG_STR(SIGVTALRM, "Virtual timer expired");
|
|
|
|
CASE_SIG_STR(SIGPROF, "Profiling timer expired");
|
2023-08-01 19:27:13 +08:00
|
|
|
CASE_SIG_STR(SIGWINCH, "Window resize signal");
|
2023-03-21 22:56:51 +08:00
|
|
|
CASE_SIG_STR(SIGPOLL, "Pollable event occurred");
|
|
|
|
CASE_SIG_STR(SIGSYS, "Bad system call");
|
|
|
|
|
|
|
|
#endif /* CONFIG_LIBC_STRSIGNAL */
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (signum >= SIGRTMIN && signum <= SIGRTMAX)
|
|
|
|
{
|
|
|
|
snprintf(sigstr, sizeof(sigstr), "Real-time Signal %d",
|
|
|
|
signum - SIGRTMIN);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
snprintf(sigstr, sizeof(sigstr), "Signal %d", signum);
|
|
|
|
}
|
|
|
|
break;
|
2018-09-18 03:55:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return a string devoid is meaning */
|
|
|
|
|
2023-03-21 22:56:51 +08:00
|
|
|
return sigstr;
|
2018-09-18 03:55:33 +08:00
|
|
|
}
|