mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-24 13:50:08 +00:00
use some fancy compiler magic (thanks to Matthew Woehlke on the gcc-help mailing list) to restore type-safety to S_OR by going back to a macro, but preserve the side-effect-safe usage of the macro arguments
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@155967 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -52,19 +52,13 @@ static force_inline int ast_strlen_zero(const char *s)
|
|||||||
/*! \brief returns the equivalent of logic or for strings:
|
/*! \brief returns the equivalent of logic or for strings:
|
||||||
* first one if not empty, otherwise second one.
|
* first one if not empty, otherwise second one.
|
||||||
*/
|
*/
|
||||||
static force_inline char *S_OR(const char *a, const char *b)
|
#define S_OR(a, b) ({typeof(&((a)[0])) __x = (a); ast_strlen_zero(__x) ? (b) : __x;})
|
||||||
{
|
|
||||||
return ast_strlen_zero(a) ? (char *) b : (char *) a;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*! \brief returns the equivalent of logic or for strings, with an additional boolean check:
|
/*! \brief returns the equivalent of logic or for strings, with an additional boolean check:
|
||||||
* second one if not empty and first one is true, otherwise third one.
|
* second one if not empty and first one is true, otherwise third one.
|
||||||
* example: S_COR(usewidget, widget, "<no widget>")
|
* example: S_COR(usewidget, widget, "<no widget>")
|
||||||
*/
|
*/
|
||||||
static force_inline char *S_COR(unsigned char a, const char *b, const char *c)
|
#define S_COR(a, b, c) ({typeof(&((b)[0])) __x = (b); (a) && !ast_strlen_zero(__x) ? (__x) : (c);})
|
||||||
{
|
|
||||||
return a && !ast_strlen_zero(b) ? (char *) b : (char *) c;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Gets a pointer to the first non-whitespace character in a string.
|
\brief Gets a pointer to the first non-whitespace character in a string.
|
||||||
|
|||||||
Reference in New Issue
Block a user