wcsrtombs.c revision 227753
1175164Sjhb/*-
2225344Srwatson * Copyright (c) 2002-2004 Tim J. Robbins.
3175164Sjhb * All rights reserved.
4175164Sjhb *
5175164Sjhb * Copyright (c) 2011 The FreeBSD Foundation
6175164Sjhb * All rights reserved.
7175164Sjhb * Portions of this software were developed by David Chisnall
8175164Sjhb * under sponsorship from the FreeBSD Foundation.
9175164Sjhb *
10175164Sjhb * Redistribution and use in source and binary forms, with or without
11175164Sjhb * modification, are permitted provided that the following conditions
12175164Sjhb * are met:
13175164Sjhb * 1. Redistributions of source code must retain the above copyright
14175164Sjhb *    notice, this list of conditions and the following disclaimer.
15175164Sjhb * 2. Redistributions in binary form must reproduce the above copyright
16175164Sjhb *    notice, this list of conditions and the following disclaimer in the
17175164Sjhb *    documentation and/or other materials provided with the distribution.
18175164Sjhb *
19175164Sjhb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20175164Sjhb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21175164Sjhb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22175164Sjhb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23175164Sjhb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24175164Sjhb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25175164Sjhb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26175164Sjhb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27175164Sjhb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28175164Sjhb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29175164Sjhb * SUCH DAMAGE.
30175164Sjhb */
31175164Sjhb
32175164Sjhb#include <sys/cdefs.h>
33175164Sjhb__FBSDID("$FreeBSD: head/lib/libc/locale/wcsrtombs.c 227753 2011-11-20 14:45:42Z theraven $");
34225344Srwatson
35175164Sjhb#include <limits.h>
36175164Sjhb#include <stdlib.h>
37175164Sjhb#include <string.h>
38225344Srwatson#include <wchar.h>
39175164Sjhb#include "mblocal.h"
40225344Srwatson
41175164Sjhbsize_t
42175164Sjhbwcsrtombs_l(char * __restrict dst, const wchar_t ** __restrict src, size_t len,
43225344Srwatson    mbstate_t * __restrict ps, locale_t locale)
44175164Sjhb{
45175164Sjhb	FIX_LOCALE(locale);
46175164Sjhb	if (ps == NULL)
47175164Sjhb		ps = &locale->wcsrtombs;
48175164Sjhb	return (XLOCALE_CTYPE(locale)->__wcsnrtombs(dst, src, SIZE_T_MAX, len, ps));
49175164Sjhb}
50175164Sjhb
51175164Sjhbsize_t
52175164Sjhbwcsrtombs(char * __restrict dst, const wchar_t ** __restrict src, size_t len,
53175164Sjhb    mbstate_t * __restrict ps)
54223692Sjonathan{
55223692Sjonathan	return wcsrtombs_l(dst, src, len, ps, __get_locale());
56175164Sjhb}
57223692Sjonathan