strsignal.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*
  2. * libcompat - system compatibility library
  3. *
  4. * Copyright © 1995 Ian Jackson <ijackson@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 published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This is distributed in the hope that it will be useful,
  12. * but 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 <https://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. #include "compat.h"
  25. #define _(str) gettext(str)
  26. #if !HAVE_DECL_SYS_SIGLIST
  27. const char *const sys_siglist[] = {
  28. NULL, /* 0 */
  29. "SIGHUP", /* 1 */
  30. "SIGINT", /* 2 */
  31. "SIGQUIT", /* 3 */
  32. "SIGILL", /* 4 */
  33. "SIGTRAP", /* 5 */
  34. "SIGABRT", /* 6 */
  35. "SIGEMT", /* 7 */
  36. "SIGFPE", /* 8 */
  37. "SIGKILL", /* 9 */
  38. "SIGUSR1", /* 10 */
  39. "SIGSEGV", /* 11 */
  40. "SIGUSR2", /* 12 */
  41. "SIGPIPE", /* 13 */
  42. "SIGALRM", /* 14 */
  43. "SIGTERM", /* 15 */
  44. "SIGSTKFLT", /* 16 */
  45. "SIGCHLD", /* 17 */
  46. "SIGCONT", /* 18 */
  47. "SIGSTOP", /* 19 */
  48. "SIGTSTP", /* 20 */
  49. "SIGTTIN", /* 21 */
  50. "SIGTTOU", /* 22 */
  51. };
  52. # define COMPAT_NSIGLIST (int)(sizeof(sys_siglist) / sizeof(sys_siglist[0]))
  53. #else
  54. # ifndef NSIG
  55. # define NSIG 32
  56. # endif
  57. # define COMPAT_NSIGLIST NSIG
  58. #endif
  59. const char *
  60. strsignal(int s)
  61. {
  62. static char buf[100];
  63. if (s > 0 && s < COMPAT_NSIGLIST)
  64. return sys_siglist[s];
  65. sprintf(buf, _("Unknown signal %d"), s);
  66. return buf;
  67. }