You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.8KB

  1. /*-------------------------------------------------------------------------
  2. *
  3. * pgstrsignal.c
  4. * Identify a Unix signal number
  5. *
  6. * On platforms compliant with modern POSIX, this just wraps strsignal(3).
  7. * Elsewhere, we do the best we can.
  8. *
  9. * This file is not currently built in MSVC builds, since it's useless
  10. * on non-Unix platforms.
  11. *
  12. * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
  13. * Portions Copyright (c) 1994, Regents of the University of California
  14. *
  15. * IDENTIFICATION
  16. * src/port/pgstrsignal.c
  17. *
  18. *-------------------------------------------------------------------------
  19. */
  20. #include "c.h"
  21. /*
  22. * pg_strsignal
  23. *
  24. * Return a string identifying the given Unix signal number.
  25. *
  26. * The result is declared "const char *" because callers should not
  27. * modify the string. Note, however, that POSIX does not promise that
  28. * the string will remain valid across later calls to strsignal().
  29. *
  30. * This version guarantees to return a non-NULL pointer, although
  31. * some platforms' versions of strsignal() reputedly do not.
  32. *
  33. * Note that the fallback cases just return constant strings such as
  34. * "unrecognized signal". Project style is for callers to print the
  35. * numeric signal value along with the result of this function, so
  36. * there's no need to work harder than that.
  37. */
  38. const char *
  39. pg_strsignal(int signum)
  40. {
  41. const char *result;
  42. /*
  43. * If we have strsignal(3), use that --- but check its result for NULL.
  44. */
  45. #ifdef HAVE_STRSIGNAL
  46. result = strsignal(signum);
  47. if (result == NULL)
  48. result = "unrecognized signal";
  49. #else
  50. /*
  51. * We used to have code here to try to use sys_siglist[] if available.
  52. * However, it seems that all platforms with sys_siglist[] have also had
  53. * strsignal() for many years now, so that was just a waste of code.
  54. */
  55. result = "(signal names not available on this platform)";
  56. #endif
  57. return result;
  58. }