1*4a39ccd0Sderaadt /* $OpenBSD: mbstowcs.c,v 1.2 2012/12/05 23:20:00 deraadt Exp $ */
2c9b8e388Sstsp
3c9b8e388Sstsp /*-
4c9b8e388Sstsp * Copyright (c) 2002-2004 Tim J. Robbins.
5c9b8e388Sstsp * All rights reserved.
6c9b8e388Sstsp *
7c9b8e388Sstsp * Redistribution and use in source and binary forms, with or without
8c9b8e388Sstsp * modification, are permitted provided that the following conditions
9c9b8e388Sstsp * are met:
10c9b8e388Sstsp * 1. Redistributions of source code must retain the above copyright
11c9b8e388Sstsp * notice, this list of conditions and the following disclaimer.
12c9b8e388Sstsp * 2. Redistributions in binary form must reproduce the above copyright
13c9b8e388Sstsp * notice, this list of conditions and the following disclaimer in the
14c9b8e388Sstsp * documentation and/or other materials provided with the distribution.
15c9b8e388Sstsp *
16c9b8e388Sstsp * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17c9b8e388Sstsp * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18c9b8e388Sstsp * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19c9b8e388Sstsp * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20c9b8e388Sstsp * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21c9b8e388Sstsp * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22c9b8e388Sstsp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23c9b8e388Sstsp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24c9b8e388Sstsp * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25c9b8e388Sstsp * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26c9b8e388Sstsp * SUCH DAMAGE.
27c9b8e388Sstsp */
28c9b8e388Sstsp
29c9b8e388Sstsp
30c9b8e388Sstsp #include <limits.h>
31c9b8e388Sstsp #include <stdlib.h>
32c9b8e388Sstsp #include <string.h>
33c9b8e388Sstsp #include <wchar.h>
34c9b8e388Sstsp
35c9b8e388Sstsp size_t
mbstowcs(wchar_t * __restrict pwcs,const char * __restrict s,size_t n)36c9b8e388Sstsp mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n)
37c9b8e388Sstsp {
38c9b8e388Sstsp mbstate_t mbs;
39c9b8e388Sstsp const char *sp;
40c9b8e388Sstsp
41c9b8e388Sstsp memset(&mbs, 0, sizeof(mbs));
42c9b8e388Sstsp sp = s;
43c9b8e388Sstsp return (mbsrtowcs(pwcs, &sp, n, &mbs));
44c9b8e388Sstsp }
45