summaryrefslogtreecommitdiffstats
path: root/src/compat/strnlen.c
blob: 07db4a44a27725cf0377d8580d0f93baa8b3250b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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;
}