123a1cceRoger A. Faulkner/*
223a1cceRoger A. Faulkner * CDDL HEADER START
323a1cceRoger A. Faulkner *
423a1cceRoger A. Faulkner * The contents of this file are subject to the terms of the
523a1cceRoger A. Faulkner * Common Development and Distribution License (the "License").
623a1cceRoger A. Faulkner * You may not use this file except in compliance with the License.
723a1cceRoger A. Faulkner *
823a1cceRoger A. Faulkner * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
923a1cceRoger A. Faulkner * or http://www.opensolaris.org/os/licensing.
1023a1cceRoger A. Faulkner * See the License for the specific language governing permissions
1123a1cceRoger A. Faulkner * and limitations under the License.
1223a1cceRoger A. Faulkner *
1323a1cceRoger A. Faulkner * When distributing Covered Code, include this CDDL HEADER in each
1423a1cceRoger A. Faulkner * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1523a1cceRoger A. Faulkner * If applicable, add the following below this CDDL HEADER, with the
1623a1cceRoger A. Faulkner * fields enclosed by brackets "[]" replaced with your own identifying
1723a1cceRoger A. Faulkner * information: Portions Copyright [yyyy] [name of copyright owner]
1823a1cceRoger A. Faulkner *
1923a1cceRoger A. Faulkner * CDDL HEADER END
2023a1cceRoger A. Faulkner */
2123a1cceRoger A. Faulkner
2223a1cceRoger A. Faulkner/*
2323a1cceRoger A. Faulkner * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2423a1cceRoger A. Faulkner */
2523a1cceRoger A. Faulkner
2623a1cceRoger A. Faulkner/*
2723a1cceRoger A. Faulkner * Returns the number of non-NULL characters in str,
2823a1cceRoger A. Faulkner * but not more than maxlen.  Does not look past str + maxlen.
2923a1cceRoger A. Faulkner */
3023a1cceRoger A. Faulkner
3123a1cceRoger A. Faulkner#include "lint.h"
3223a1cceRoger A. Faulkner#include <stdlib.h>
3323a1cceRoger A. Faulkner#include <wchar.h>
3423a1cceRoger A. Faulkner
3523a1cceRoger A. Faulknersize_t
3623a1cceRoger A. Faulknerwcsnlen(const wchar_t *str, size_t maxlen)
3723a1cceRoger A. Faulkner{
3823a1cceRoger A. Faulkner	const wchar_t *ptr = str;
3923a1cceRoger A. Faulkner
4023a1cceRoger A. Faulkner	if (maxlen != 0) {
4123a1cceRoger A. Faulkner		do {
4223a1cceRoger A. Faulkner			if (*ptr++ == L'\0') {
4323a1cceRoger A. Faulkner				ptr--;
4423a1cceRoger A. Faulkner				break;
4523a1cceRoger A. Faulkner			}
4623a1cceRoger A. Faulkner		} while (--maxlen != 0);
4723a1cceRoger A. Faulkner	}
4823a1cceRoger A. Faulkner
4923a1cceRoger A. Faulkner	return (ptr - str);
5023a1cceRoger A. Faulkner}