[tor-commits] [tor/master] Define a strnlen replacement on platforms (win32) that lack it
nickm at torproject.org
nickm at torproject.org
Mon Oct 13 18:59:50 UTC 2014
commit 21fe945ebd7183685bf5bbcd80bf6b1b946eb841
Author: Nick Mathewson <nickm at torproject.org>
Date: Mon Oct 13 14:59:17 2014 -0400
Define a strnlen replacement on platforms (win32) that lack it
Right now this is only needed for test_util_format_time_interval, so
define it as a static function. We can move it into compat later if
we need to.
---
configure.ac | 1 +
src/test/test_util.c | 11 +++++++++++
2 files changed, 12 insertions(+)
diff --git a/configure.ac b/configure.ac
index c0523e1..4c7da5d 100644
--- a/configure.ac
+++ b/configure.ac
@@ -365,6 +365,7 @@ AC_CHECK_FUNCS(
socketpair \
strlcat \
strlcpy \
+ strnlen \
strptime \
strtok_r \
strtoull \
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 8855caf..eb169f4 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -2072,6 +2072,17 @@ test_util_sscanf(void *arg)
#define tt_char_op(a,op,b) tt_assert_op_type(a,op,b,char,"%c")
#define tt_ci_char_op(a,op,b) tt_char_op(tolower(a),op,tolower(b))
+#ifndef HAVE_STRNLEN
+static size_t
+strnlen(const char *s, size_t len)
+{
+ const char *p = memchr(s, 0, len);
+ if (!p)
+ return len;
+ return p - s;
+}
+#endif
+
static void
test_util_format_time_interval(void *arg)
{
More information about the tor-commits
mailing list