AC_CONFIG_LIBOBJ_DIR([src/compat])
AC_FUNC_MALLOC
AC_FUNC_REALLOC
-AC_REPLACE_FUNCS([strlcpy])
+AC_REPLACE_FUNCS([strlcpy strnlen])
AC_CHECK_FUNCS([setresuid setresgid])
AC_SEARCH_LIBS([__res_init], resolv bind, AC_DEFINE([HAVE_RES_INIT], 1, [Define to indicate that res_init() exists]),
size_t strlcpy(char *, const char *, size_t);
#endif
+#if !HAVE_STRNLEN
+size_t strnlen(const char *, size_t);
+#endif
+
#if !HAVE_MALLOC
void *malloc(size_t size);
#endif
--- /dev/null
+/* -*- mode: c; c-file-style: "openbsd" -*- */
+
+#include <string.h>
+
+/*
+ * Determine the length of a fixed-size string. This is really a
+ * wrapper around `memchr()`.
+ */
+size_t
+strnlen(const char *string, size_t maxlen)
+{
+ const char *end = memchr(string, '\0', maxlen);
+ return end?(size_t)(end - string):maxlen;
+}