Add an implementation of strnlen for MinGW, as it does not provide
that function in its runtime library.
---
 include/babeltrace/compat/string.h | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/include/babeltrace/compat/string.h 
b/include/babeltrace/compat/string.h
index 1db5837..14e7b53 100644
--- a/include/babeltrace/compat/string.h
+++ b/include/babeltrace/compat/string.h
@@ -44,6 +44,30 @@ static inline char* strtok_r(
        return ret;
 }
 
+static inline
+size_t strnlen(const char *str, size_t maxlen)
+{
+       char * ptr;
+       size_t len;
+
+       ptr = (char *)str;
+       len = 0;
+
+       /* while there still are characters in the string */
+       while(*ptr != '\0') {
+               /* increment counter */
+               len++;
+               /* check that we do not exceed the given maximum */
+               if (len == maxlen) {
+                       return len;
+               }
+               /* next character */
+               ptr++;
+
+       }
+       return len;
+}
+
 static inline int compat_strerror_r(int errnum, char *buf, size_t buflen)
 {
        /* non-recursive implementation of strerror_r */
-- 
1.8.1.msysgit.1


_______________________________________________
lttng-dev mailing list
[email protected]
http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

Reply via email to