aboutsummaryrefslogtreecommitdiff
path: root/src/string_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/string_util.c')
-rw-r--r--src/string_util.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/string_util.c b/src/string_util.c
index b76b257b..5d9feccf 100644
--- a/src/string_util.c
+++ b/src/string_util.c
@@ -48,6 +48,21 @@ string_array_contains(const char *const* haystack, const char *needle)
return false;
}
+#ifndef HAVE_STRNLEN
+
+size_t
+strnlen(const char *s, size_t max)
+{
+ assert(s != NULL);
+
+ const char *t = memchr(s, 0, max);
+ return t != NULL
+ ? (size_t)(t - s)
+ : max;
+}
+
+#endif
+
#if !defined(HAVE_STRNDUP)
char *