]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Define a strnlen replacement on platforms (win32) that lack it
authorNick Mathewson <nickm@torproject.org>
Mon, 13 Oct 2014 18:59:17 +0000 (14:59 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 13 Oct 2014 18:59:17 +0000 (14:59 -0400)
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
src/test/test_util.c

index c0523e10820fb5b5a61535b8d0272a1bb3f72a5b..4c7da5d76a06d4af0a56e9b80f7cd12e4e905754 100644 (file)
@@ -365,6 +365,7 @@ AC_CHECK_FUNCS(
         socketpair \
         strlcat \
         strlcpy \
+       strnlen \
         strptime \
         strtok_r \
         strtoull \
index 8855cafc120429c53641666fe176a57755ac0e91..eb169f4dd58c5dee615542800fe32adc9581676c 100644 (file)
@@ -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)
 {