summaryrefslogtreecommitdiff
path: root/strfuncs.h
diff options
context:
space:
mode:
authorZbigniew Chyla <zbigniew.chyla@nsn.com>2015-01-16 15:46:59 +0100
committerEric S. Raymond <esr@thyrsus.com>2015-01-21 10:47:59 -0500
commit152463c594cece47e3a7a0f37e6667d39437c164 (patch)
tree93f82c0fa324c2a2b83f2b64bc3aa19bc5e25478 /strfuncs.h
parent9b07a07f6fed92d1b041bfcd8a49ca7314f75ac3 (diff)
downloadgpsd-152463c594cece47e3a7a0f37e6667d39437c164.tar.gz
Convert macros in strfuncs.h to functions.
Diffstat (limited to 'strfuncs.h')
-rw-r--r--strfuncs.h40
1 files changed, 29 insertions, 11 deletions
diff --git a/strfuncs.h b/strfuncs.h
index b7911d99..fa5a7d3f 100644
--- a/strfuncs.h
+++ b/strfuncs.h
@@ -8,21 +8,39 @@
#define _GPSD_STRFUNCS_H_
#include <stdarg.h>
+#include <stdbool.h>
#include <stdio.h>
#include <string.h>
+#include "compiler.h"
-#define str_starts_with(str, prefix) \
- (strncmp((str), (prefix), strlen(prefix)) == 0)
-#define str_appendf(str, alloc_size, format, ...) \
- ((void) snprintf((str) + strlen(str), (alloc_size) - strlen(str), (format), ##__VA_ARGS__))
-#define str_vappendf(str, alloc_size, format, ap) \
- ((void) vsnprintf((str) + strlen(str), (alloc_size) - strlen(str), (format), (ap)))
+static inline bool str_starts_with(const char *str, const char *prefix)
+{
+ return strncmp(str, prefix, strlen(prefix)) == 0;
+}
-#define str_rstrip_char(str, ch) \
- do { \
- if ((str)[strlen(str) - 1] == ch) \
- (str)[strlen(str) - 1] = '\0'; \
- } while (0)
+
+PRINTF_FUNC(3, 4)
+static inline void str_appendf(char *str, size_t alloc_size, const char *format, ...)
+{
+ va_list ap;
+ va_start(ap, format);
+ (void) vsnprintf(str + strlen(str), alloc_size - strlen(str), format, ap);
+ va_end(ap);
+}
+
+
+static inline void str_vappendf(char *str, size_t alloc_size, const char *format, va_list ap)
+{
+ (void) vsnprintf(str + strlen(str), alloc_size - strlen(str), format, ap);
+}
+
+
+static inline void str_rstrip_char(char *str, char ch)
+{
+ if (str[strlen(str) - 1] == ch) {
+ str[strlen(str) - 1] = '\0';
+ }
+}
#endif /* _GPSD_STRFUNCS_H_ */