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