aboutsummaryrefslogtreecommitdiff
path: root/src/core/strs.c
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2017-12-27 17:36:24 -0800
committerGarrett D'Amore <garrett@damore.org>2017-12-27 17:36:24 -0800
commit1fc48dc4a67503c65a040606bc00a4cac7210f13 (patch)
tree4ea220a46b4223d75bd08405df354ff5b368018c /src/core/strs.c
parent5ff3d3d3ab82be4b2171e06f1def9cdddaef4115 (diff)
downloadnng-1fc48dc4a67503c65a040606bc00a4cac7210f13.tar.gz
nng-1fc48dc4a67503c65a040606bc00a4cac7210f13.tar.bz2
nng-1fc48dc4a67503c65a040606bc00a4cac7210f13.zip
Compilation fixes for Windows.
Diffstat (limited to 'src/core/strs.c')
-rw-r--r--src/core/strs.c33
1 files changed, 28 insertions, 5 deletions
diff --git a/src/core/strs.c b/src/core/strs.c
index a03c0bb5..66a385d0 100644
--- a/src/core/strs.c
+++ b/src/core/strs.c
@@ -134,14 +134,35 @@ nni_strcasestr(const char *s1, const char *s2)
}
int
+nni_strcasecmp(const char *s1, const char *s2)
+{
+#if defined(_WIN32)
+ return (_stricmp(s1, s2));
+#elif defined(NNG_HAVE_STRCASECMP)
+ return (strcasecmp(s1, s2));
+#else
+ for (;;) {
+ uint8_t c1 = (uint8_t) tolower(*s1++);
+ uint8_t c2 = (uint8_t) tolower(*s2++);
+ if (c1 == c2) {
+ if (c1 == 0) {
+ return (0);
+ }
+ continue;
+ }
+ return ((c1 < c2) ? -1 : 1);
+ }
+ return (0);
+#endif
+}
+
+int
nni_strncasecmp(const char *s1, const char *s2, size_t n)
{
-#ifdef NNG_HAVE_STRNCASECMP
-#ifdef _WIN32
+#if defined(_WIN32)
return (_strnicmp(s1, s2, n));
-#else
+#elif defined(NNG_HAVE_STRNCASECMP)
return (strncasecmp(s1, s2, n));
-#endif
#else
for (int i = 0; i < n; i++) {
uint8_t c1 = (uint8_t) tolower(*s1++);
@@ -152,12 +173,14 @@ nni_strncasecmp(const char *s1, const char *s2, size_t n)
}
continue;
}
- return (c1 < c2 ? -1 : 1);
+ return ((c1 < c2) ? -1 : 1);
}
return (0);
#endif
}
+// As with strdup, we always use our own, so that our strings
+// can be freed with nni_strfree().
int
nni_asprintf(char **sp, const char *fmt, ...)
{