strsignal.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * libcompat - system compatibility library
  3. *
  4. * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  5. *
  6. * This is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2,
  9. * or (at your option) any later version.
  10. *
  11. * This is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <config.h>
  20. #include <signal.h>
  21. #include <string.h>
  22. #include <stdio.h>
  23. #include <gettext.h>
  24. #define _(str) gettext(str)
  25. #ifndef HAVE_DECL_SYS_SIGLIST
  26. const char *const sys_siglist[] = {
  27. NULL, /* 0 */
  28. "SIGHUP", /* 1 */
  29. "SIGINT", /* 2 */
  30. "SIGQUIT", /* 3 */
  31. "SIGILL", /* 4 */
  32. "SIGTRAP", /* 5 */
  33. "SIGABRT", /* 6 */
  34. "SIGEMT", /* 7 */
  35. "SIGFPE", /* 8 */
  36. "SIGKILL", /* 9 */
  37. "SIGUSR1", /* 10 */
  38. "SIGSEGV", /* 11 */
  39. "SIGUSR2", /* 12 */
  40. "SIGPIPE", /* 13 */
  41. "SIGALRM", /* 14 */
  42. "SIGTERM", /* 15 */
  43. "SIGSTKFLT", /* 16 */
  44. "SIGCHLD", /* 17 */
  45. "SIGCONT", /* 18 */
  46. "SIGSTOP", /* 19 */
  47. "SIGTSTP", /* 20 */
  48. "SIGTTIN", /* 21 */
  49. "SIGTTOU", /* 22 */
  50. };
  51. #else
  52. extern const char *const sys_siglist[];
  53. #endif
  54. #ifndef HAVE_STRSIGNAL
  55. const char *
  56. strsignal(int s)
  57. {
  58. static char buf[100];
  59. if (s > 0 && s < sizeof(sys_siglist) / sizeof(sys_siglist[0]))
  60. return sys_siglist[s];
  61. sprintf(buf, _("Unknown signal %d"), s);
  62. return buf;
  63. }
  64. #endif