From c57435c96de0eab7f0415af7ddf2fc7f4852100e Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 2 May 2008 16:07:13 +0200 Subject: [PATCH] [util] Add a_strtobool() function Signed-off-by: Julien Danjou --- common/util.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/common/util.h b/common/util.h index 940b1eac3..cf44f0c95 100644 --- a/common/util.h +++ b/common/util.h @@ -248,6 +248,25 @@ a_strncat(char *dst, ssize_t n, const char *src, ssize_t l) return dlen + a_strncpy(dst + dlen, n - dlen, src, l); } +/** \brief convert a string to a boolean value. + * + * The a_strtobool() function converts a string \c s into a boolean. + * It recognizes the strings "true", "on", "yes" and "1". + * + * \param[in] s the string to convert + * \return true if the string is recognized as possibly true, false otherwise. + */ +static inline bool +a_strtobool(const char *s) +{ + if(!strcasecmp(s, "true") + || !strcasecmp(s, "on") + || !strcasecmp(s, "yes") + || !strcasecmp(s, "1")) + return true; + return false; +} + #define eprint(string, ...) _eprint(__LINE__, \ __FUNCTION__, \ string, ## __VA_ARGS__)