Add g_strsignal() to string_calls module

This commit is contained in:
matt335672
2023-06-08 15:57:17 +01:00
parent a2798fe9e9
commit 0f32661056
4 changed files with 33 additions and 3 deletions
+24
View File
@@ -422,6 +422,30 @@ g_atoi(const char *str)
return atoi(str);
}
/*****************************************************************************/
char *
g_strsignal(int signum)
{
char *result = strsignal(signum);
if (result == NULL)
{
// Using a static buffer offers the same guarantees as the
// strsignal() call
static char buff[32];
unsigned int len;
len = g_snprintf(buff, sizeof(buff), "SIG#%d", signum);
if (len >= sizeof(buff))
{
// Buffer overflow
g_snprintf(buff, sizeof(buff), "SIG???");
}
result = buff;
}
return result;
}
/*****************************************************************************/
/* As g_atoi() but allows for hexadecimal too */
int
+6
View File
@@ -266,6 +266,12 @@ int g_strncmp_d(const char *c1, const char *c2, const char delim, int len);
int g_strcasecmp(const char *c1, const char *c2);
int g_strncasecmp(const char *c1, const char *c2, int len);
int g_atoi(const char *str);
/**
* Implements POSIX 1003.1 strsignal()
*
* This function never returns NULL
*/
char *g_strsignal(int signum);
/**
* Extends g_atoi(), Converts decimal and hexadecimal number String to integer
*
+1 -1
View File
@@ -821,7 +821,7 @@ exit_status_to_str(const struct exit_status *e, char buff[], int bufflen)
break;
case E_XR_SIGNAL:
g_snprintf(buff, bufflen, "signal %d", e->val);
g_snprintf(buff, bufflen, "signal \"%s\"", g_strsignal(e->val));
break;
default:
+2 -2
View File
@@ -156,8 +156,8 @@ wait_for_xserver(uid_t uid,
case E_XR_SIGNAL:
LOG(LOG_LEVEL_ERROR,
"waitforx failed with unexpected signal %d",
e.val);
"waitforx failed with unexpected signal \"%s\"",
g_strsignal(e.val));
break;
default: