1239844Sdes/*	$OpenBSD: strnlen.c,v 1.3 2010/06/02 12:58:12 millert Exp $	*/
2239844Sdes
3239844Sdes/*
4239844Sdes * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com>
5239844Sdes *
6239844Sdes * Permission to use, copy, modify, and distribute this software for any
7239844Sdes * purpose with or without fee is hereby granted, provided that the above
8239844Sdes * copyright notice and this permission notice appear in all copies.
9239844Sdes *
10239844Sdes * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11239844Sdes * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12239844Sdes * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13239844Sdes * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14239844Sdes * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15239844Sdes * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16239844Sdes * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17239844Sdes */
18239844Sdes
19239844Sdes/* OPENBSD ORIGINAL: lib/libc/string/strnlen.c */
20239844Sdes
21239844Sdes#include "config.h"
22239844Sdes#ifndef HAVE_STRNLEN
23239844Sdes#include <sys/types.h>
24239844Sdes
25239844Sdes#include <string.h>
26239844Sdes
27239844Sdessize_t
28239844Sdesstrnlen(const char *str, size_t maxlen)
29239844Sdes{
30239844Sdes	const char *cp;
31239844Sdes
32239844Sdes	for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--)
33239844Sdes		;
34239844Sdes
35239844Sdes	return (size_t)(cp - str);
36239844Sdes}
37239844Sdes#endif
38