mbrlen.c revision 129154
1185029Spjd/*- 2185029Spjd * Copyright (c) 2002-2004 Tim J. Robbins. 3213136Spjd * All rights reserved. 4185029Spjd * 5185029Spjd * Redistribution and use in source and binary forms, with or without 6185029Spjd * modification, are permitted provided that the following conditions 7185029Spjd * are met: 8185029Spjd * 1. Redistributions of source code must retain the above copyright 9185029Spjd * notice, this list of conditions and the following disclaimer. 10185029Spjd * 2. Redistributions in binary form must reproduce the above copyright 11185029Spjd * notice, this list of conditions and the following disclaimer in the 12185029Spjd * documentation and/or other materials provided with the distribution. 13185029Spjd * 14185029Spjd * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15185029Spjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16185029Spjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17213136Spjd * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18225530Savg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19185029Spjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20185029Spjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21185029Spjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22185029Spjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23213136Spjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24213136Spjd * SUCH DAMAGE. 25185029Spjd */ 26185029Spjd 27185029Spjd#include <sys/cdefs.h> 28185029Spjd__FBSDID("$FreeBSD: head/lib/libc/locale/mbrlen.c 129154 2004-05-12 14:26:54Z tjr $"); 29185029Spjd 30185029Spjd#include <wchar.h> 31185029Spjd#include "mblocal.h" 32185029Spjd 33185029Spjdsize_t 34218893Sdimmbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps) 35218893Sdim{ 36218893Sdim static mbstate_t mbs; 37218893Sdim 38218893Sdim if (ps == NULL) 39185029Spjd ps = &mbs; 40185029Spjd return (__mbrtowc(NULL, s, n, ps)); 41185029Spjd} 42185029Spjd