1adecd3c6Sdg /* 2adecd3c6Sdg * CDDL HEADER START 3adecd3c6Sdg * 4adecd3c6Sdg * The contents of this file are subject to the terms of the 5adecd3c6Sdg * Common Development and Distribution License (the "License"). 6adecd3c6Sdg * You may not use this file except in compliance with the License. 7adecd3c6Sdg * 8adecd3c6Sdg * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9adecd3c6Sdg * or http://www.opensolaris.org/os/licensing. 10adecd3c6Sdg * See the License for the specific language governing permissions 11adecd3c6Sdg * and limitations under the License. 12adecd3c6Sdg * 13adecd3c6Sdg * When distributing Covered Code, include this CDDL HEADER in each 14adecd3c6Sdg * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15adecd3c6Sdg * If applicable, add the following below this CDDL HEADER, with the 16adecd3c6Sdg * fields enclosed by brackets "[]" replaced with your own identifying 17adecd3c6Sdg * information: Portions Copyright [yyyy] [name of copyright owner] 18adecd3c6Sdg * 19adecd3c6Sdg * CDDL HEADER END 20adecd3c6Sdg */ 21adecd3c6Sdg 22adecd3c6Sdg /* 23*7257d1b4Sraf * Copyright 2008 Sun Microsystems, Inc. 24adecd3c6Sdg * All rights reserved. Use is subject to license terms. 25adecd3c6Sdg */ 26adecd3c6Sdg 27*7257d1b4Sraf #include "lint.h" 28adecd3c6Sdg #include <string.h> 29adecd3c6Sdg #include <sys/types.h> 30adecd3c6Sdg 31adecd3c6Sdg /* 32adecd3c6Sdg * Returns the number of non-NULL bytes in string argument, 33adecd3c6Sdg * but not more than maxlen. Does not look past str + maxlen. 34adecd3c6Sdg */ 35adecd3c6Sdg size_t strnlen(const char * str,size_t maxlen)36adecd3c6Sdgstrnlen(const char *str, size_t maxlen) 37adecd3c6Sdg { 38adecd3c6Sdg const char *ptr; 39adecd3c6Sdg 40adecd3c6Sdg ptr = memchr(str, 0, maxlen); 41adecd3c6Sdg if (ptr == NULL) 42adecd3c6Sdg return (maxlen); 43adecd3c6Sdg 44adecd3c6Sdg return (ptr - str); 45adecd3c6Sdg } 46