Add g_strsignal() to string_calls module
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
*
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user