This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: strsignal.c implementation
- From: Joel Sherrill <joel dot sherrill at oarcorp dot com>
- To: Jeff Johnston <jjohnstn at redhat dot com>
- Cc: "newlib at sourceware dot org" <newlib at sourceware dot org>
- Date: Tue, 11 May 2010 11:24:21 -0500
- Subject: Re: strsignal.c implementation
- References: <4BE95AF8.8060109@oarcorp.com> <4BE97C87.9050505@redhat.com>
On 05/11/2010 10:49 AM, Jeff Johnston wrote:
On 05/11/2010 09:26 AM, Joel Sherrill wrote:
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?
Yes, IMO it is worth it to make it a shared implementation. Option 2 is
what is used in libc/string/strerror.c for the errno strings.
How about the attached version? I went through the list of
signals and added everyone in sys/signal.h. When the values
could be the same, I added a little extra conditional magic
to see if both were defined and the same to avoid
duplicate case errors.
2010-05-11 Joel Sherrill <joel.sherrill@oarcorp.com>
* libc/string/strsignal.c: New file.
-- Jeff J.
--
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>
const char *
strsignal (int signal)
{
char *buffer;
struct _reent *ptr;
ptr = _REENT;
_REENT_CHECK_SIGNAL_BUF(ptr);
buffer = _REENT_SIGNAL_BUF(ptr);
#if defined(SIGRTMIN) && defined(SIGRTMAX)
if ((signal >= SIGRTMIN) || (signal <= SIGRTMAX)) {
siprintf (buffer, "Real-time signal %d", signal - SIGRTMIN);
return buffer;
}
#endif
switch (signal) {
#ifdef SIGHUP
case SIGHUP:
buffer = "Hangup";
break;
#endif
#ifdef SIGINT
case SIGINT:
buffer = "Interrupt";
break;
#endif
#ifdef SIGQUIT
case SIGQUIT:
buffer = "Quit";
break;
#endif
#ifdef SIGILL
case SIGILL:
buffer = "Illegal instruction";
break;
#endif
#ifdef SIGTRAP
case SIGTRAP:
buffer = "Trace/breakpoint trap";
break;
#endif
#ifdef SIGIOT
#if defined(SIGABRT) && (SIGIOT != SIGABRT)
case SIGABRT:
#endif
case SIGIOT:
buffer = "IOT trap";
break;
#endif
#ifdef SIGEMT
case SIGEMT:
buffer = "EMT trap";
break;
#endif
#ifdef SIGFPE
case SIGFPE:
buffer = "Floating point exception";
break;
#endif
#ifdef SIGKILL
case SIGKILL:
buffer = "Killed";
break;
#endif
#ifdef SIGBUS
case SIGBUS:
buffer = "Bus error";
break;
#endif
#ifdef SIGSEGV
case SIGSEGV:
buffer = "Segmentation fault";
break;
#endif
#ifdef SIGSYS
case SIGSYS:
buffer = "Bad system call";
break;
#endif
#ifdef SIGPIPE
case SIGPIPE:
buffer = "Broken pipe";
break;
#endif
#ifdef SIGALRM
case SIGALRM:
buffer = "Alarm clock";
break;
#endif
#ifdef SIGTERM
case SIGTERM:
buffer = "Terminated";
break;
#endif
#ifdef SIGURG
case SIGURG:
buffer = "Urgent I/O condition";
break;
#endif
#ifdef SIGSTOP
case SIGSTOP:
buffer = "Stopped (signal)";
break;
#endif
#ifdef SIGTSTP
case SIGTSTP:
buffer = "Stopped";
break;
#endif
#ifdef SIGCONT
case SIGCONT:
buffer = "Continued";
break;
#endif
#ifdef SIGCHLD
#if defined(SIGCLD) && (SIGCHLD != SIGCLD)
case SIGCLD:
#endif
case SIGCHLD:
buffer = "Child exited";
break;
#endif
#ifdef SIGTTIN
case SIGTTIN:
buffer = "Stopped (tty input)";
break;
#endif
#ifdef SIGTTOUT
case SIGTTOUT:
buffer = "Stopped (tty output)";
break;
#endif
#ifdef SIGIO
#if defined(SIGPOLL) && (SIGIO != SIGPOLL)
case SIGPOLL:
#endif
case SIGIO:
buffer = "I/O possible";
break;
#endif
#ifdef SIGWINCH
case SIGWINCH:
buffer = "Window changed";
break;
#endif
#ifdef SIGUSR1
case SIGUSR1:
buffer = "User defined signal 1";
break;
#endif
#ifdef SIGUSR2
case SIGUSR2:
buffer = "User defined signal 2";
break;
#endif
#ifdef SIGPWR
case SIGPWR:
buffer = "Power Failure";
break;
#endif
#ifdef SIGXCPU
case SIGXCPU:
buffer = "CPU time limit exceeded";
break;
#endif
#ifdef SIGXFSZ
case SIGXFSZ:
buffer = "File size limit exceeded";
break;
#endif
#ifdef SIGVTALRM
case SIGVTALRM :
buffer = "Virtual timer expired";
break;
#endif
#ifdef SIGPROF
case SIGPROF:
buffer = "Profiling timer expired";
break;
#endif
#ifdef SIGLOST
case SIGLOST:
buffer = "Resource lost";
break;
#endif
default:
siprintf (buffer, "Unknown signal %d", signal);
break;
}
return buffer;
}