diff --git a/examples/api_server/Makefile b/examples/api_server/Makefile
index 49910c1771861b94c13bb425b05f66e1179ff5bc..9aeeaa3f83100511f1337286768d3d27a896bc42 100644
--- a/examples/api_server/Makefile
+++ b/examples/api_server/Makefile
@@ -4,7 +4,7 @@ CFLAGS = -W -Wall $(CFLAGS_EXTRA)
 
 
 ifeq ($(OS), Windows_NT)
-  CFLAGS += -lws2_32 -D_MG_PROVIDE_STRNLEN
+  CFLAGS += -lws2_32
   CC = gcc
 else
   UNAME_S := $(shell uname -s)
diff --git a/examples/examples.mk b/examples/examples.mk
index 45e66abbeb83184deaaffa356e0b37fb0b085f42..b912a076c83b257116999908c6721378f810a428 100644
--- a/examples/examples.mk
+++ b/examples/examples.mk
@@ -5,7 +5,7 @@ all: $(PROG)
 
 ifeq ($(OS), Windows_NT)
 # TODO(alashkin): enable SSL in Windows
-CFLAGS += -lws2_32 -D_MG_PROVIDE_STRNLEN
+CFLAGS += -lws2_32
 CC = gcc
 else
 ifeq ($(SSL_LIB),openssl)
diff --git a/mongoose.c b/mongoose.c
index 38883ccb3278d4672f0ae0a967f8dea5078cdf90..ebe19438c170c961e228ce8f5dd123cb55fb1e47 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -1751,14 +1751,12 @@ void cs_hmac_sha1(const unsigned char *key, size_t keylen,
 /* Amalgamated: #include "common/platform.h" */
 /* Amalgamated: #include "common/str_util.h" */
 
-#ifdef _MG_PROVIDE_STRNLEN
-size_t strnlen(const char *s, size_t maxlen) {
+size_t c_strnlen(const char *s, size_t maxlen) {
   size_t l = 0;
   for (; l < maxlen && s[l] != '\0'; l++) {
   }
   return l;
 }
-#endif
 
 #define C_SNPRINTF_APPEND_CHAR(ch)       \
   do {                                   \
@@ -1887,7 +1885,7 @@ int c_vsnprintf(char *buf, size_t buf_size, const char *fmt, va_list ap) {
       if (ch == 's') {
         const char *s = va_arg(ap, const char *); /* Always fetch parameter */
         int j;
-        int pad = field_width - (precision >= 0 ? strnlen(s, precision) : 0);
+        int pad = field_width - (precision >= 0 ? c_strnlen(s, precision) : 0);
         for (j = 0; j < pad; j++) {
           C_SNPRINTF_APPEND_CHAR(' ');
         }
diff --git a/mongoose.h b/mongoose.h
index cccec29ad82382a9fc280ce7cf21e6aebea6b66b..3c5b68173e07d49dea1a05d5710a909794822d6f 100644
--- a/mongoose.h
+++ b/mongoose.h
@@ -857,6 +857,7 @@ int cs_base64_decode(const unsigned char *s, int len, char *dst);
 extern "C" {
 #endif
 
+size_t c_strnlen(const char *s, size_t maxlen);
 int c_snprintf(char *buf, size_t buf_size, const char *format, ...);
 int c_vsnprintf(char *buf, size_t buf_size, const char *format, va_list ap);
 /*
@@ -865,15 +866,6 @@ int c_vsnprintf(char *buf, size_t buf_size, const char *format, va_list ap);
  */
 const char *c_strnstr(const char *s, const char *find, size_t slen);
 
-#if (!(defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 700) &&           \
-     !(defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200809L) &&   \
-     !(defined(__DARWIN_C_LEVEL) && __DARWIN_C_LEVEL >= 200809L) && \
-     !defined(RTOS_SDK)) &&                                         \
-    !(defined(_MSC_VER) && _MSC_VER >= 1600 /* MSVC2010+ has strnlen */)
-#define _MG_PROVIDE_STRNLEN
-size_t strnlen(const char *s, size_t maxlen);
-#endif
-
 #ifdef __cplusplus
 }
 #endif