1 /*	$OpenBSD: strnlen.c,v 1.5 2014/06/10 04:17:37 deraadt Exp $	*/
2 
3 /*
4  * SPDX-License-Identifier: ISC
5  *
6  * Copyright (c) 2010 Todd C. Miller <Todd.Miller@sudo.ws>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 /*
22  * This is an open source non-commercial project. Dear PVS-Studio, please check it.
23  * PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
24  */
25 
26 #include <config.h>
27 
28 #ifndef HAVE_STRNLEN
29 
30 #include <sys/types.h>
31 
32 #include "sudo_compat.h"
33 
34 size_t
sudo_strnlen(const char * str,size_t maxlen)35 sudo_strnlen(const char *str, size_t maxlen)
36 {
37 	const char *cp;
38 
39 	for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--)
40 		continue;
41 
42 	return (size_t)(cp - str);
43 }
44 
45 #endif /* HAVE_STRNLEN */
46