summaryrefslogtreecommitdiffstats
path: root/src/compat/strnlen.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 18:02:34 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 18:02:34 +0000
commitfadeddfbb2aa38a980dd959b5ec1ffba7afd43cb (patch)
treea7bde6111c84ea64619656a38fba50909fa0bf60 /src/compat/strnlen.c
parentInitial commit. (diff)
downloadlldpd-upstream.tar.xz
lldpd-upstream.zip
Adding upstream version 1.0.18.upstream/1.0.18upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r--src/compat/strnlen.c15
1 files changed, 15 insertions, 0 deletions
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 <string.h>
+#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;
+}