adecd3c68045d04dc367d30faf2eb5cac1f45d5adg/*
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * CDDL HEADER START
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg *
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * The contents of this file are subject to the terms of the
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * Common Development and Distribution License (the "License").
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * You may not use this file except in compliance with the License.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg *
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * or http://www.opensolaris.org/os/licensing.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * See the License for the specific language governing permissions
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * and limitations under the License.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg *
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * When distributing Covered Code, include this CDDL HEADER in each
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * If applicable, add the following below this CDDL HEADER, with the
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * fields enclosed by brackets "[]" replaced with your own identifying
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * information: Portions Copyright [yyyy] [name of copyright owner]
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg *
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * CDDL HEADER END
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg */
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg/*
7257d1b4d25bfac0c802847390e98a464fd787acraf * Copyright 2008 Sun Microsystems, Inc.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * All rights reserved. Use is subject to license terms.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg */
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg#pragma ident "%Z%%M% %I% %E% SMI"
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg
7257d1b4d25bfac0c802847390e98a464fd787acraf#include "lint.h"
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg#include <string.h>
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg#include <sys/types.h>
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg/*
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * Returns the number of non-NULL bytes in string argument,
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg * but not more than maxlen. Does not look past str + maxlen.
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg */
adecd3c68045d04dc367d30faf2eb5cac1f45d5adgsize_t
adecd3c68045d04dc367d30faf2eb5cac1f45d5adgstrnlen(const char *str, size_t maxlen)
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg{
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg const char *ptr;
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg ptr = memchr(str, 0, maxlen);
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg if (ptr == NULL)
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg return (maxlen);
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg return (ptr - str);
adecd3c68045d04dc367d30faf2eb5cac1f45d5adg}