From fadeddfbb2aa38a980dd959b5ec1ffba7afd43cb Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 20:02:34 +0200 Subject: Adding upstream version 1.0.18. Signed-off-by: Daniel Baumann --- src/compat/strnlen.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 src/compat/strnlen.c (limited to 'src/compat/strnlen.c') diff --git a/src/compat/strnlen.c b/src/compat/strnlen.c new file mode 100644 index 0000000..07db4a4 --- /dev/null +++ b/src/compat/strnlen.c @@ -0,0 +1,15 @@ +/* -*- mode: c; c-file-style: "openbsd" -*- */ + +#include +#include "compat.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; +} -- cgit v1.2.3