]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/Stdio/vswprintf.c
2 * Copyright (c) 1997 Todd C. Miller <Todd.Miller@courtesan.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
17 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 FreeBSD: src/lib/libc/stdio/vswprintf.c,v 1.6 2005/02/21 19:41:44 fjoe Exp
28 NetBSD: vswprintf.c,v 1.1 2005/05/14 23:51:02 christos Exp
30 #include <LibConfig.h>
31 #include <sys/EfiCdefs.h>
38 #include "reentrant.h"
42 vswprintf(wchar_t * __restrict s
, size_t n
, const wchar_t * __restrict fmt
,
45 static const mbstate_t initial
= { 0 };
51 struct __sfileext fext
;
58 _FILEEXT_SETUP(&f
, &fext
);
60 f
._flags
= __SWR
| __SSTR
| __SALC
;
61 f
._bf
._base
= f
._p
= (unsigned char *)malloc(128);
62 if (f
._bf
._base
== NULL
) {
66 f
._bf
._size
= f
._w
= 127; /* Leave room for the NUL */
67 ret
= __vfwprintf_unlocked(&f
, fmt
, ap
);
75 mbp
= (char *)f
._bf
._base
;
77 * XXX Undo the conversion from wide characters to multibyte that
78 * fputwc() did in __vfwprintf().
81 nwc
= mbsrtowcs(s
, (const char **)&mbp
, n
, &mbs
);
83 if (nwc
== (size_t)-1) {