116dcf40des/* $OpenBSD: strnlen.c,v 1.3 2010/06/02 12:58:12 millert Exp $ */ 216dcf40des 316dcf40des/* 416dcf40des * Copyright (c) 2010 Todd C. Miller <Todd.Miller@courtesan.com> 516dcf40des * 616dcf40des * Permission to use, copy, modify, and distribute this software for any 716dcf40des * purpose with or without fee is hereby granted, provided that the above 816dcf40des * copyright notice and this permission notice appear in all copies. 916dcf40des * 1016dcf40des * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1116dcf40des * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1216dcf40des * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1316dcf40des * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1416dcf40des * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1516dcf40des * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1616dcf40des * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1716dcf40des */ 1816dcf40des 1916dcf40des/* OPENBSD ORIGINAL: lib/libc/string/strnlen.c */ 2016dcf40des 21705433fdes#include "includes.h" 22441eac4des#if !defined(HAVE_STRNLEN) || defined(BROKEN_STRNLEN) 2316dcf40des#include <sys/types.h> 2416dcf40des 2516dcf40des#include <string.h> 2616dcf40des 2716dcf40dessize_t 2816dcf40desstrnlen(const char *str, size_t maxlen) 2916dcf40des{ 3016dcf40des const char *cp; 3116dcf40des 3216dcf40des for (cp = str; maxlen != 0 && *cp != '\0'; cp++, maxlen--) 3316dcf40des ; 3416dcf40des 3516dcf40des return (size_t)(cp - str); 3616dcf40des} 3716dcf40des#endif 38