From eb2c2b6e6ebd80f51ba3bd09177563f7640fa0b0 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Tue, 11 May 2010 20:27:20 +0000 Subject: [PATCH] 2010-05-11 Joel Sherrill * libc/string/strsignal.c: New file. * libc/string/Makefile.am: Add support for strsignal. * libc/string/strings.tex: Ditto. * libc/string/Makefile.in: Regenerated. --- newlib/ChangeLog | 7 + newlib/libc/string/Makefile.am | 3 +- newlib/libc/string/Makefile.in | 54 ++++--- newlib/libc/string/strings.tex | 4 + newlib/libc/string/strsignal.c | 256 +++++++++++++++++++++++++++++++++ 5 files changed, 300 insertions(+), 24 deletions(-) create mode 100644 newlib/libc/string/strsignal.c diff --git a/newlib/ChangeLog b/newlib/ChangeLog index ac505c0ca..d938fb248 100644 --- a/newlib/ChangeLog +++ b/newlib/ChangeLog @@ -1,3 +1,10 @@ +2010-05-11 Joel Sherrill + + * libc/string/strsignal.c: New file. + * libc/string/Makefile.am: Add support for strsignal. + * libc/string/strings.tex: Ditto. + * libc/string/Makefile.in: Regenerated. + 2010-05-05 DJ Delorie * libc/Makefile.am (stmp-sigset, stmp-iconvset, stmp-extra, diff --git a/newlib/libc/string/Makefile.am b/newlib/libc/string/Makefile.am index be7bf50a0..82fec8be1 100644 --- a/newlib/libc/string/Makefile.am +++ b/newlib/libc/string/Makefile.am @@ -37,6 +37,7 @@ GENERAL_SOURCES = \ strpbrk.c \ strrchr.c \ strsep.c \ + strsignal.c \ strspn.c \ strtok.c \ strtok_r.c \ @@ -129,7 +130,7 @@ index.def rindex.def strcspn.def strpbrk.def swab.def \ memchr.def strcat.def strerror.def strerror_r.def strrchr.def \ memcmp.def strchr.def strlen.def strnlen.def strspn.def \ strcasecmp.def strncasecmp.def strcasestr.def strlwr.def strupr.def \ -memccpy.def mempcpy.def stpcpy.def stpncpy.def \ +memccpy.def mempcpy.def stpcpy.def stpncpy.def strsignal.def \ wcscasecmp.def wcscat.def wcschr.def wcscmp.def wcscoll.def \ wcscpy.def wcscspn.def wcpcpy.def wcpncpy.def wcsdup.def \ wcslcat.def wcslcpy.def wcslen.def wcsncasecmp.def wcsncat.def \ diff --git a/newlib/libc/string/Makefile.in b/newlib/libc/string/Makefile.in index a57304116..1a7b4cae5 100644 --- a/newlib/libc/string/Makefile.in +++ b/newlib/libc/string/Makefile.in @@ -71,23 +71,24 @@ am__objects_1 = lib_a-bcopy.$(OBJEXT) lib_a-bzero.$(OBJEXT) \ lib_a-strncmp.$(OBJEXT) lib_a-strncpy.$(OBJEXT) \ lib_a-strnlen.$(OBJEXT) lib_a-strpbrk.$(OBJEXT) \ lib_a-strrchr.$(OBJEXT) lib_a-strsep.$(OBJEXT) \ - lib_a-strspn.$(OBJEXT) lib_a-strtok.$(OBJEXT) \ - lib_a-strtok_r.$(OBJEXT) lib_a-strupr.$(OBJEXT) \ - lib_a-strxfrm.$(OBJEXT) lib_a-strstr.$(OBJEXT) \ - lib_a-swab.$(OBJEXT) lib_a-u_strerr.$(OBJEXT) \ - lib_a-wcscat.$(OBJEXT) lib_a-wcschr.$(OBJEXT) \ - lib_a-wcscmp.$(OBJEXT) lib_a-wcscoll.$(OBJEXT) \ - lib_a-wcscpy.$(OBJEXT) lib_a-wcscspn.$(OBJEXT) \ - lib_a-wcslcat.$(OBJEXT) lib_a-wcslcpy.$(OBJEXT) \ - lib_a-wcslen.$(OBJEXT) lib_a-wcsncat.$(OBJEXT) \ - lib_a-wcsncmp.$(OBJEXT) lib_a-wcsncpy.$(OBJEXT) \ - lib_a-wcsnlen.$(OBJEXT) lib_a-wcspbrk.$(OBJEXT) \ - lib_a-wcsrchr.$(OBJEXT) lib_a-wcsspn.$(OBJEXT) \ - lib_a-wcsstr.$(OBJEXT) lib_a-wcstok.$(OBJEXT) \ - lib_a-wcswidth.$(OBJEXT) lib_a-wcsxfrm.$(OBJEXT) \ - lib_a-wcwidth.$(OBJEXT) lib_a-wmemchr.$(OBJEXT) \ - lib_a-wmemcmp.$(OBJEXT) lib_a-wmemcpy.$(OBJEXT) \ - lib_a-wmemmove.$(OBJEXT) lib_a-wmemset.$(OBJEXT) + lib_a-strsignal.$(OBJEXT) lib_a-strspn.$(OBJEXT) \ + lib_a-strtok.$(OBJEXT) lib_a-strtok_r.$(OBJEXT) \ + lib_a-strupr.$(OBJEXT) lib_a-strxfrm.$(OBJEXT) \ + lib_a-strstr.$(OBJEXT) lib_a-swab.$(OBJEXT) \ + lib_a-u_strerr.$(OBJEXT) lib_a-wcscat.$(OBJEXT) \ + lib_a-wcschr.$(OBJEXT) lib_a-wcscmp.$(OBJEXT) \ + lib_a-wcscoll.$(OBJEXT) lib_a-wcscpy.$(OBJEXT) \ + lib_a-wcscspn.$(OBJEXT) lib_a-wcslcat.$(OBJEXT) \ + lib_a-wcslcpy.$(OBJEXT) lib_a-wcslen.$(OBJEXT) \ + lib_a-wcsncat.$(OBJEXT) lib_a-wcsncmp.$(OBJEXT) \ + lib_a-wcsncpy.$(OBJEXT) lib_a-wcsnlen.$(OBJEXT) \ + lib_a-wcspbrk.$(OBJEXT) lib_a-wcsrchr.$(OBJEXT) \ + lib_a-wcsspn.$(OBJEXT) lib_a-wcsstr.$(OBJEXT) \ + lib_a-wcstok.$(OBJEXT) lib_a-wcswidth.$(OBJEXT) \ + lib_a-wcsxfrm.$(OBJEXT) lib_a-wcwidth.$(OBJEXT) \ + lib_a-wmemchr.$(OBJEXT) lib_a-wmemcmp.$(OBJEXT) \ + lib_a-wmemcpy.$(OBJEXT) lib_a-wmemmove.$(OBJEXT) \ + lib_a-wmemset.$(OBJEXT) @ELIX_LEVEL_1_FALSE@am__objects_2 = lib_a-bcmp.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@ lib_a-memccpy.$(OBJEXT) \ @ELIX_LEVEL_1_FALSE@ lib_a-mempcpy.$(OBJEXT) \ @@ -113,11 +114,11 @@ am__objects_4 = bcopy.lo bzero.lo index.lo memchr.lo memcmp.lo \ strdup.lo strdup_r.lo strerror.lo strerror_r.lo strlcat.lo \ strlcpy.lo strlen.lo strlwr.lo strncasecmp.lo strncat.lo \ strncmp.lo strncpy.lo strnlen.lo strpbrk.lo strrchr.lo \ - strsep.lo strspn.lo strtok.lo strtok_r.lo strupr.lo strxfrm.lo \ - strstr.lo swab.lo u_strerr.lo wcscat.lo wcschr.lo wcscmp.lo \ - wcscoll.lo wcscpy.lo wcscspn.lo wcslcat.lo wcslcpy.lo \ - wcslen.lo wcsncat.lo wcsncmp.lo wcsncpy.lo wcsnlen.lo \ - wcspbrk.lo wcsrchr.lo wcsspn.lo wcsstr.lo wcstok.lo \ + strsep.lo strsignal.lo strspn.lo strtok.lo strtok_r.lo \ + strupr.lo strxfrm.lo strstr.lo swab.lo u_strerr.lo wcscat.lo \ + wcschr.lo wcscmp.lo wcscoll.lo wcscpy.lo wcscspn.lo wcslcat.lo \ + wcslcpy.lo wcslen.lo wcsncat.lo wcsncmp.lo wcsncpy.lo \ + wcsnlen.lo wcspbrk.lo wcsrchr.lo wcsspn.lo wcsstr.lo wcstok.lo \ wcswidth.lo wcsxfrm.lo wcwidth.lo wmemchr.lo wmemcmp.lo \ wmemcpy.lo wmemmove.lo wmemset.lo @ELIX_LEVEL_1_FALSE@am__objects_5 = bcmp.lo memccpy.lo mempcpy.lo \ @@ -327,6 +328,7 @@ GENERAL_SOURCES = \ strpbrk.c \ strrchr.c \ strsep.c \ + strsignal.c \ strspn.c \ strtok.c \ strtok_r.c \ @@ -400,7 +402,7 @@ index.def rindex.def strcspn.def strpbrk.def swab.def \ memchr.def strcat.def strerror.def strerror_r.def strrchr.def \ memcmp.def strchr.def strlen.def strnlen.def strspn.def \ strcasecmp.def strncasecmp.def strcasestr.def strlwr.def strupr.def \ -memccpy.def mempcpy.def stpcpy.def stpncpy.def \ +memccpy.def mempcpy.def stpcpy.def stpncpy.def strsignal.def \ wcscasecmp.def wcscat.def wcschr.def wcscmp.def wcscoll.def \ wcscpy.def wcscspn.def wcpcpy.def wcpncpy.def wcsdup.def \ wcslcat.def wcslcpy.def wcslen.def wcsncasecmp.def wcsncat.def \ @@ -674,6 +676,12 @@ lib_a-strsep.o: strsep.c lib_a-strsep.obj: strsep.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strsep.obj `if test -f 'strsep.c'; then $(CYGPATH_W) 'strsep.c'; else $(CYGPATH_W) '$(srcdir)/strsep.c'; fi` +lib_a-strsignal.o: strsignal.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strsignal.o `test -f 'strsignal.c' || echo '$(srcdir)/'`strsignal.c + +lib_a-strsignal.obj: strsignal.c + $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strsignal.obj `if test -f 'strsignal.c'; then $(CYGPATH_W) 'strsignal.c'; else $(CYGPATH_W) '$(srcdir)/strsignal.c'; fi` + lib_a-strspn.o: strspn.c $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(lib_a_CFLAGS) $(CFLAGS) -c -o lib_a-strspn.o `test -f 'strspn.c' || echo '$(srcdir)/'`strspn.c diff --git a/newlib/libc/string/strings.tex b/newlib/libc/string/strings.tex index 2e2c7fd73..ae00a261a 100644 --- a/newlib/libc/string/strings.tex +++ b/newlib/libc/string/strings.tex @@ -40,6 +40,7 @@ managing areas of memory. The corresponding declarations are in * strnlen:: Character string length * strpbrk:: Find chars in string * strrchr:: Reverse search for character in string +* strsignal:: Return signal message string * strspn:: Find initial match * strstr:: Find string segment * strtok:: Get next token from a string @@ -153,6 +154,9 @@ managing areas of memory. The corresponding declarations are in @page @include string/strrchr.def +@page +@include string/strsignal.def + @page @include string/strspn.def diff --git a/newlib/libc/string/strsignal.c b/newlib/libc/string/strsignal.c new file mode 100644 index 000000000..6d39e8b75 --- /dev/null +++ b/newlib/libc/string/strsignal.c @@ -0,0 +1,256 @@ +/* +FUNCTION + <>---convert signal number to string + +INDEX + strsignal + +ANSI_SYNOPSIS + #include + char *strsignal(int <[signal]>); + +TRAD_SYNOPSIS + #include + char *strsignal(<[signal]>) + int <[signal]>; + +DESCRIPTION +<> converts the signal number <[signal]> into a +string. If <[signal]> is not a known signal number, the result +will be of the form "Unknown signal NN" where NN is the <[signal]> +is a decimal number. + +RETURNS +This function returns a pointer to a string. Your application must +not modify that string. + +PORTABILITY +POSIX.1-2008 C requires <>, but does not specify the strings used +for each signal number. + +<> requires no supporting OS subroutines. + +QUICKREF + strsignal pure +*/ + +/* + * Written by Joel Sherrill . + * + * 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 +#include +#include +#include + +char * +_DEFUN (strsignal, (signal), + 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; +}