Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /*
  2. FUNCTION
  3.         <<strsignal>>---convert signal number to string
  4.  
  5. INDEX
  6.         strsignal
  7.  
  8. ANSI_SYNOPSIS
  9.         #include <string.h>
  10.         char *strsignal(int <[signal]>);
  11.  
  12. TRAD_SYNOPSIS
  13.         #include <string.h>
  14.         char *strsignal(<[signal]>)
  15.         int <[signal]>;
  16.  
  17. DESCRIPTION
  18. <<strsignal>> converts the signal number <[signal]> into a
  19. string.  If <[signal]> is not a known signal number, the result
  20. will be of the form "Unknown signal NN" where NN is the <[signal]>
  21. is a decimal number.
  22.  
  23. RETURNS
  24. This function returns a pointer to a string.  Your application must
  25. not modify that string.
  26.  
  27. PORTABILITY
  28. POSIX.1-2008 C requires <<strsignal>>, but does not specify the strings used
  29. for each signal number.
  30.  
  31. <<strsignal>> requires no supporting OS subroutines.
  32.  
  33. QUICKREF
  34.         strsignal pure
  35. */
  36.  
  37. /*
  38.  *  Written by Joel Sherrill <joel.sherrill@OARcorp.com>.
  39.  *
  40.  *  COPYRIGHT (c) 2010.
  41.  *  On-Line Applications Research Corporation (OAR).
  42.  *
  43.  *  Permission to use, copy, modify, and distribute this software for any
  44.  *  purpose without fee is hereby granted, provided that this entire notice
  45.  *  is included in all copies of any software which is or includes a copy
  46.  *  or modification of this software.
  47.  *
  48.  *  THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
  49.  *  WARRANTY.  IN PARTICULAR,  THE AUTHOR MAKES NO REPRESENTATION
  50.  *  OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
  51.  *  SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
  52.  *
  53.  *  $Id$
  54.  */
  55.  
  56. #include <string.h>
  57. #include <signal.h>
  58. #include <stdio.h>
  59. #include <reent.h>
  60.  
  61. char *
  62. _DEFUN (strsignal, (signal),
  63.         int signal)
  64. {
  65.   char *buffer;
  66.   struct _reent *ptr;
  67.  
  68.   ptr = _REENT;
  69.  
  70.   _REENT_CHECK_SIGNAL_BUF(ptr);
  71.   buffer = _REENT_SIGNAL_BUF(ptr);
  72.  
  73. #if defined(SIGRTMIN) && defined(SIGRTMAX)
  74.   if ((signal >= SIGRTMIN) || (signal <= SIGRTMAX)) {
  75.     siprintf (buffer, "Real-time signal %d", signal - SIGRTMIN);
  76.     return buffer;
  77.   }
  78. #endif
  79.  
  80.   switch (signal) {
  81. #ifdef SIGHUP
  82.     case SIGHUP:
  83.       buffer = "Hangup";
  84.       break;
  85. #endif
  86. #ifdef SIGINT
  87.     case SIGINT:
  88.       buffer = "Interrupt";
  89.       break;
  90. #endif
  91. #ifdef SIGQUIT
  92.     case SIGQUIT:
  93.       buffer = "Quit";
  94.       break;
  95. #endif
  96. #ifdef SIGILL
  97.     case SIGILL:
  98.       buffer = "Illegal instruction";
  99.       break;
  100. #endif
  101. #ifdef SIGTRAP
  102.     case SIGTRAP:
  103.       buffer = "Trace/breakpoint trap";
  104.       break;
  105. #endif
  106. #ifdef SIGIOT
  107.   #if  defined(SIGABRT) && (SIGIOT != SIGABRT)
  108.     case SIGABRT:
  109.   #endif
  110.     case SIGIOT:
  111.       buffer = "IOT trap";
  112.       break;
  113. #endif
  114. #ifdef SIGEMT
  115.     case SIGEMT:
  116.       buffer = "EMT trap";
  117.       break;
  118. #endif
  119. #ifdef SIGFPE
  120.     case SIGFPE:
  121.       buffer = "Floating point exception";
  122.       break;
  123. #endif
  124. #ifdef SIGKILL
  125.     case SIGKILL:
  126.       buffer = "Killed";
  127.       break;
  128. #endif
  129. #ifdef SIGBUS
  130.     case SIGBUS:
  131.       buffer = "Bus error";
  132.       break;
  133. #endif
  134. #ifdef SIGSEGV
  135.     case SIGSEGV:
  136.       buffer = "Segmentation fault";
  137.       break;
  138. #endif
  139. #ifdef SIGSYS
  140.     case SIGSYS:
  141.       buffer = "Bad system call";
  142.       break;
  143. #endif
  144. #ifdef SIGPIPE
  145.     case SIGPIPE:
  146.       buffer = "Broken pipe";
  147.       break;
  148. #endif
  149. #ifdef SIGALRM
  150.     case SIGALRM:
  151.       buffer = "Alarm clock";
  152.       break;
  153. #endif
  154. #ifdef SIGTERM
  155.     case SIGTERM:
  156.       buffer = "Terminated";
  157.       break;
  158. #endif
  159. #ifdef SIGURG
  160.     case SIGURG:
  161.       buffer = "Urgent I/O condition";
  162.       break;
  163. #endif
  164. #ifdef SIGSTOP
  165.     case SIGSTOP:
  166.       buffer = "Stopped (signal)";
  167.       break;
  168. #endif
  169. #ifdef SIGTSTP
  170.     case SIGTSTP:
  171.       buffer = "Stopped";
  172.       break;
  173. #endif
  174. #ifdef SIGCONT
  175.     case SIGCONT:
  176.       buffer = "Continued";
  177.       break;
  178. #endif
  179. #ifdef SIGCHLD
  180.   #if  defined(SIGCLD) && (SIGCHLD != SIGCLD)
  181.     case SIGCLD:
  182.   #endif
  183.     case SIGCHLD:
  184.       buffer = "Child exited";
  185.       break;
  186. #endif
  187. #ifdef SIGTTIN
  188.     case SIGTTIN:
  189.       buffer = "Stopped (tty input)";
  190.       break;
  191. #endif
  192. #ifdef SIGTTOUT
  193.     case SIGTTOUT:
  194.       buffer = "Stopped (tty output)";
  195.       break;
  196. #endif
  197. #ifdef SIGIO
  198.   #if  defined(SIGPOLL) && (SIGIO != SIGPOLL)
  199.     case SIGPOLL:
  200.   #endif
  201.     case SIGIO:
  202.       buffer = "I/O possible";
  203.       break;
  204. #endif
  205. #ifdef SIGWINCH
  206.     case SIGWINCH:
  207.       buffer = "Window changed";
  208.       break;
  209. #endif
  210. #ifdef SIGUSR1
  211.     case SIGUSR1:
  212.       buffer = "User defined signal 1";
  213.       break;
  214. #endif
  215. #ifdef SIGUSR2
  216.     case SIGUSR2:
  217.       buffer = "User defined signal 2";
  218.       break;
  219. #endif
  220. #ifdef SIGPWR
  221.     case SIGPWR:
  222.       buffer = "Power Failure";
  223.       break;
  224. #endif
  225. #ifdef SIGXCPU
  226.     case SIGXCPU:
  227.       buffer = "CPU time limit exceeded";
  228.       break;
  229. #endif
  230. #ifdef SIGXFSZ
  231.     case SIGXFSZ:
  232.       buffer = "File size limit exceeded";
  233.       break;
  234. #endif
  235. #ifdef SIGVTALRM
  236.     case SIGVTALRM :
  237.       buffer = "Virtual timer expired";
  238.       break;
  239. #endif
  240. #ifdef SIGPROF
  241.     case SIGPROF:
  242.       buffer = "Profiling timer expired";
  243.       break;
  244. #endif
  245. #if defined(SIGLOST) && SIGLOST != SIGPWR
  246.     case SIGLOST:
  247.       buffer = "Resource lost";
  248.       break;
  249. #endif
  250.     default:
  251.       siprintf (buffer, "Unknown signal %d", signal);
  252.       break;
  253.   }
  254.  
  255.   return buffer;
  256. }
  257.