[waffle] [PATCH 14/33] c99: add snprintf and strcasecmp
Emil Velikov
emil.l.velikov at gmail.com
Mon Jul 7 10:28:21 PDT 2014
Another two C99 functions missing from msvc 2013...
Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
---
include/c99_compat.h | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 44 insertions(+)
diff --git a/include/c99_compat.h b/include/c99_compat.h
index dc0977f..bc8ddc6 100644
--- a/include/c99_compat.h
+++ b/include/c99_compat.h
@@ -53,3 +53,47 @@
# define inline
# endif
#endif
+
+/*
+ * C99 string manipulation functions - snprintf, strcasecmp
+ *
+ * http://stackoverflow.com/questions/2915672/snprintf-and-visual-studio-2010
+ */
+#if defined(_MSC_VER)
+#include <stdarg.h> // for va_start, va_end
+#include <stdio.h> // for _vscprintf, _vscprintf_s
+#include <string.h>
+
+#define strcasecmp _stricmp
+#define snprintf c99_snprintf
+
+static inline int
+c99_vsnprintf(char* str, size_t size, const char* format, va_list ap)
+{
+ int count = -1;
+
+ if (size != 0)
+ count = _vsnprintf_s(str, size, _TRUNCATE, format, ap);
+ if (count == -1)
+ count = _vscprintf(format, ap);
+
+ return count;
+}
+
+static inline int
+c99_snprintf(char* str, size_t size, const char* format, ...)
+{
+ int count;
+ va_list ap;
+
+ va_start(ap, format);
+ count = c99_vsnprintf(str, size, format, ap);
+ va_end(ap);
+
+ return count;
+}
+
+#else
+#include <strings.h>
+
+#endif
--
2.0.0
More information about the waffle
mailing list