This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
strsignal.c implementation
- From: Joel Sherrill <joel dot sherrill at oarcorp dot com>
- To: "newlib at sources dot redhat dot com" <newlib at sources dot redhat dot com>
- Date: Tue, 11 May 2010 08:26:16 -0500
- Subject: strsignal.c implementation
Hi,
I have implemented strsignal.c for RTEMS but
wondered if it was worth trying to make the
implementation match the ifdef's in sys/signal.h
and support other targets?
I have attached the current implementation. I
see two approaches to making it support all
the targets:
+ ifdefs in the table to match the numbers in
sys/signal.h.
+ a long series of code something like this:
#ifdef SIGXXX
if ( signal == SIGXXX )
return "string for SIGXXX";
#endif
Any thoughts or comments?
--
Joel Sherrill, Ph.D. Director of Research& Development
joel.sherrill@OARcorp.com On-Line Applications Research
Ask me about RTEMS: a free RTOS Huntsville AL 35805
Support Available (256) 722-9985
/*
* Written by Joel Sherrill <joel.sherrill@OARcorp.com>.
*
* COPYRIGHT (c) 2010.
* On-Line Applications Research Corporation (OAR).
*
* Permission to use, copy, modify, and distribute this software for any
* purpose without fee is hereby granted, provided that this entire notice
* is included in all copies of any software which is or includes a copy
* or modification of this software.
*
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
* WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION
* OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
* SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
*
* $Id$
*/
#include <string.h>
#include <signal.h>
#include <stdio.h>
#include <reent.h>
static const char *signal_string[] = {
"Signal 0",
"Hangup", /* SIGHUP */
"Interrupt", /* SIGINT */
"Quit", /* SIGQUIT */
"Illegal instruction", /* SIGILL */
"Trace/breakpoint trap", /* SIGTRAP */
"IOT trap", /* SIGIOT */
"EMT trap", /* SIGEMT */
"Floating point exception", /* SIGFPE */
"Killed", /* SIGKILL */
"Bus error", /* SIGBUS */
"Segmentation fault", /* SIGSEGV */
"Bad system call", /* SIGSYS */
"Broken pipe", /* SIGPIPE */
"Alarm clock", /* SIGALRM */
"Terminated", /* SIGTERM */
"Urgent I/O condition", /* SIGURG */
"Stopped (signal)", /* SIGSTOP */
"Stopped", /* SIGTSTP */
"Continued", /* SIGCONT */
"Child exited", /* SIGCHLD */
"Stopped (tty input)", /* SIGCLD */
"Stopped (tty output)", /* SIGTTIN */
"I/O possible", /* SIGIO */
"Window changed", /* SIGWINCH */
"User defined signal 1", /* SIGUSR1 */
"User defined signal 2" /* SIGUSR2 */
};
const char *
strsignal (int signal)
{
char *buffer;
struct _reent *ptr;
ptr = _REENT;
_REENT_CHECK_SIGNAL_BUF(ptr);
buffer = _REENT_SIGNAL_BUF(ptr);
if (signal < 0 || signal > SIGRTMAX) {
siprintf (buffer, "Unknown signal %d", signal);
return buffer;
}
if ((signal >= SIGRTMIN) || (signal <= SIGRTMAX)) {
siprintf (buffer, "Real-time signal %d", signal - SIGRTMIN);
return buffer;
}
return signal_string[signal];
}