1*23a1cceaSRoger A. Faulkner /* 2*23a1cceaSRoger A. Faulkner * CDDL HEADER START 3*23a1cceaSRoger A. Faulkner * 4*23a1cceaSRoger A. Faulkner * The contents of this file are subject to the terms of the 5*23a1cceaSRoger A. Faulkner * Common Development and Distribution License (the "License"). 6*23a1cceaSRoger A. Faulkner * You may not use this file except in compliance with the License. 7*23a1cceaSRoger A. Faulkner * 8*23a1cceaSRoger A. Faulkner * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*23a1cceaSRoger A. Faulkner * or http://www.opensolaris.org/os/licensing. 10*23a1cceaSRoger A. Faulkner * See the License for the specific language governing permissions 11*23a1cceaSRoger A. Faulkner * and limitations under the License. 12*23a1cceaSRoger A. Faulkner * 13*23a1cceaSRoger A. Faulkner * When distributing Covered Code, include this CDDL HEADER in each 14*23a1cceaSRoger A. Faulkner * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*23a1cceaSRoger A. Faulkner * If applicable, add the following below this CDDL HEADER, with the 16*23a1cceaSRoger A. Faulkner * fields enclosed by brackets "[]" replaced with your own identifying 17*23a1cceaSRoger A. Faulkner * information: Portions Copyright [yyyy] [name of copyright owner] 18*23a1cceaSRoger A. Faulkner * 19*23a1cceaSRoger A. Faulkner * CDDL HEADER END 20*23a1cceaSRoger A. Faulkner */ 21*23a1cceaSRoger A. Faulkner 22*23a1cceaSRoger A. Faulkner /* 23*23a1cceaSRoger A. Faulkner * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved. 24*23a1cceaSRoger A. Faulkner */ 25*23a1cceaSRoger A. Faulkner 26*23a1cceaSRoger A. Faulkner /* 27*23a1cceaSRoger A. Faulkner * Returns the number of non-NULL characters in str, 28*23a1cceaSRoger A. Faulkner * but not more than maxlen. Does not look past str + maxlen. 29*23a1cceaSRoger A. Faulkner */ 30*23a1cceaSRoger A. Faulkner 31*23a1cceaSRoger A. Faulkner #include "lint.h" 32*23a1cceaSRoger A. Faulkner #include <stdlib.h> 33*23a1cceaSRoger A. Faulkner #include <wchar.h> 34*23a1cceaSRoger A. Faulkner 35*23a1cceaSRoger A. Faulkner size_t wcsnlen(const wchar_t * str,size_t maxlen)36*23a1cceaSRoger A. Faulknerwcsnlen(const wchar_t *str, size_t maxlen) 37*23a1cceaSRoger A. Faulkner { 38*23a1cceaSRoger A. Faulkner const wchar_t *ptr = str; 39*23a1cceaSRoger A. Faulkner 40*23a1cceaSRoger A. Faulkner if (maxlen != 0) { 41*23a1cceaSRoger A. Faulkner do { 42*23a1cceaSRoger A. Faulkner if (*ptr++ == L'\0') { 43*23a1cceaSRoger A. Faulkner ptr--; 44*23a1cceaSRoger A. Faulkner break; 45*23a1cceaSRoger A. Faulkner } 46*23a1cceaSRoger A. Faulkner } while (--maxlen != 0); 47*23a1cceaSRoger A. Faulkner } 48*23a1cceaSRoger A. Faulkner 49*23a1cceaSRoger A. Faulkner return (ptr - str); 50*23a1cceaSRoger A. Faulkner } 51