13d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes/*	$OpenBSD: mbrlen.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
23d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes
33d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes/*-
43d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * Copyright (c) 2002-2004 Tim J. Robbins.
53d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * All rights reserved.
63d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes *
73d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * Redistribution and use in source and binary forms, with or without
83d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * modification, are permitted provided that the following conditions
93d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * are met:
103d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * 1. Redistributions of source code must retain the above copyright
113d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes *    notice, this list of conditions and the following disclaimer.
123d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * 2. Redistributions in binary form must reproduce the above copyright
133d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes *    notice, this list of conditions and the following disclaimer in the
143d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes *    documentation and/or other materials provided with the distribution.
153d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes *
163d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
173d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
183d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
193d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
203d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
213d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
223d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
233d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
243d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
253d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
263d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes * SUCH DAMAGE.
273d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes */
283d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes
293d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes#include <wchar.h>
303d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes
313d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughessize_t
323d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughesmbrlen(const char * __restrict s, size_t n, mbstate_t * __restrict ps)
333d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes{
343d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes	static mbstate_t mbs;
353d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes
363d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes	if (ps == NULL)
373d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes		ps = &mbs;
383d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes	return (mbrtowc(NULL, s, n, ps));
393d7a0d9b08ecab054b2dff8332507644de3690b0Elliott Hughes}
40