summaryrefslogtreecommitdiff
path: root/include/asterisk/strings.h
diff options
context:
space:
mode:
authorKevin P. Fleming <kpfleming@digium.com>2008-11-06 21:09:24 +0000
committerKevin P. Fleming <kpfleming@digium.com>2008-11-06 21:09:24 +0000
commit433af4241aaf8f2c3c15b98b88976c385a025169 (patch)
tree5aefc0dcd1c68410b7b7af22805620430337172c /include/asterisk/strings.h
parentf08ab8278c86d084d4d98bef164bb0090dcba674 (diff)
make S_OR and S_COR safe to use even if the parameters are function calls or have side effects. it still bothers me that these are called S_OR and not something like ast_string_or, but that's water over the bridge
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@155079 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'include/asterisk/strings.h')
-rw-r--r--include/asterisk/strings.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h
index 16a60c38a..b0ab9c498 100644
--- a/include/asterisk/strings.h
+++ b/include/asterisk/strings.h
@@ -52,13 +52,19 @@ 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.
*/
-#define S_OR(a, b) (!ast_strlen_zero(a) ? (a) : (b))
+static force_inline char *S_OR(const char *a, const char *b)
+{
+ return ast_strlen_zero(a) ? (char *) b : (char *) a;
+}
/*! \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>")
*/
-#define S_COR(a, b, c) ((a && !ast_strlen_zero(b)) ? (b) : (c))
+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;
+}
/*!
\brief Gets a pointer to the first non-whitespace character in a string.