aboutsummaryrefslogtreecommitdiffstats
path: root/include/asterisk/strings.h
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-11 17:57:20 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2008-11-11 17:57:20 +0000
commited1b8e4ade9e81dc5f1e364abad0c13e2913cd27 (patch)
treeb44ecf0f9b3e7949cdf6e877d378d88596cb515e /include/asterisk/strings.h
parent82b615e21fa23e01bebc1c76ce9685963ca8a33c (diff)
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: http://svn.digium.com/svn/asterisk/trunk@155967 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'include/asterisk/strings.h')
-rw-r--r--include/asterisk/strings.h10
1 files changed, 2 insertions, 8 deletions
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index 6c5eba783..5ad362e56 100644
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -52,19 +52,13 @@ static force_inline int ast_strlen_zero(const char *s)
/*! \brief returns the equivalent of logic or for strings:
* first one if not empty, otherwise second one.
*/
-static force_inline char *S_OR(const char *a, const char *b)
-{
- return ast_strlen_zero(a) ? (char *) b : (char *) a;
-}
+#define S_OR(a, b) ({typeof(&((a)[0])) __x = (a); ast_strlen_zero(__x) ? (b) : __x;})
/*! \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.
* example: S_COR(usewidget, widget, "<no widget>")
*/
-static force_inline char *S_COR(unsigned char a, const char *b, const char *c)
-{
- return a && !ast_strlen_zero(b) ? (char *) b : (char *) c;
-}
+#define S_COR(a, b, c) ({typeof(&((b)[0])) __x = (b); (a) && !ast_strlen_zero(__x) ? (__x) : (c);})
/*!
\brief Gets a pointer to the first non-whitespace character in a string.