PostgreSQL Source Code  git master
pgstrsignal.c
Go to the documentation of this file.
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 
21 #include "c.h"
22 
23 
24 /*
25  * pg_strsignal
26  *
27  * Return a string identifying the given Unix signal number.
28  *
29  * The result is declared "const char *" because callers should not
30  * modify the string. Note, however, that POSIX does not promise that
31  * the string will remain valid across later calls to strsignal().
32  *
33  * This version guarantees to return a non-NULL pointer, although
34  * some platforms' versions of strsignal() reputedly do not.
35  *
36  * Note that the fallback cases just return constant strings such as
37  * "unrecognized signal". Project style is for callers to print the
38  * numeric signal value along with the result of this function, so
39  * there's no need to work harder than that.
40  */
41 const char *
42 pg_strsignal(int signum)
43 {
44  const char *result;
45 
46  /*
47  * If we have strsignal(3), use that --- but check its result for NULL.
48  */
49 #ifdef HAVE_STRSIGNAL
50  result = strsignal(signum);
51  if (result == NULL)
52  result = "unrecognized signal";
53 #else
54 
55  /*
56  * We used to have code here to try to use sys_siglist[] if available.
57  * However, it seems that all platforms with sys_siglist[] have also had
58  * strsignal() for many years now, so that was just a waste of code.
59  */
60  result = "(signal names not available on this platform)";
61 #endif
62 
63  return result;
64 }
const char * pg_strsignal(int signum)
Definition: pgstrsignal.c:42