mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-08-14 09:58:17 +00:00
FreeSWITCH: Add switch_strerror_r() to fix problems with XSI and GNU variants of strerror_r().
GNU variant of strerror_r() returns char *, while the XSI version returns int. To make things worse, glibc ships both and added a unused result warning in recent versions (2.16) causing the build to fail. Add our own custom wrapper that always returns a pointer to the message buffer and additionally make XSI versions of strerror_r() GNU compatible by returning "Unknown error xxx" if no error message is available. Fixes: src/switch_rtp.c: In function 'rtp_common_read': src/switch_rtp.c:3313:15: error: ignoring return value of 'strerror_r', declared with attribute warn_unused_result [-Werror=unused-result] cc1: all warnings being treated as errors Signed-off-by: Stefan Knoblich <stkn@openisdn.net>
This commit is contained in:
@@ -2968,6 +2968,31 @@ SWITCH_DECLARE(unsigned long) switch_atoul(const char *nptr)
|
||||
else return (unsigned long) tmp;
|
||||
}
|
||||
|
||||
|
||||
SWITCH_DECLARE(char *) switch_strerror_r(int errnum, char *buf, switch_size_t buflen)
|
||||
{
|
||||
#ifdef HAVE_STRERROR_R
|
||||
#ifdef STRERROR_R_CHAR_P
|
||||
/* GNU variant returning char *, avoids warn-unused-result error */
|
||||
return strerror_r(errnum, buf, buflen);
|
||||
#else
|
||||
/*
|
||||
* XSI variant returning int, with GNU compatible error string,
|
||||
* if no message could be found
|
||||
*/
|
||||
if (strerror_r(errnum, buf, buflen)) {
|
||||
switch_snprintf(buf, buflen, "Unknown error %d", errnum);
|
||||
}
|
||||
return buf;
|
||||
#endif /* STRERROR_R_CHAR_P */
|
||||
#else
|
||||
/* Fallback, copy string into private buffer */
|
||||
switch_copy_string(buf, strerror(errnum), buflen);
|
||||
return buf;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
|
Reference in New Issue
Block a user