[lttng-dev] [Babeltrace PATCH 14/23] Add MinGW implementation of strnlen
Ikaheimonen, JP
jp_ikaheimonen at mentor.com
Wed May 22 04:07:04 EDT 2013
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
More information about the lttng-dev
mailing list