]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/LibC/Stdio/fputwc.c
Standard Libraries for EDK II.
[mirror_edk2.git] / StdLib / LibC / Stdio / fputwc.c
CommitLineData
2aa62f2b 1/* $NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $ */\r
2\r
3/*-\r
4 * Copyright (c)2001 Citrus Project,\r
5 * All rights reserved.\r
6 *\r
7 * Redistribution and use in source and binary forms, with or without\r
8 * modification, are permitted provided that the following conditions\r
9 * are met:\r
10 * 1. Redistributions of source code must retain the above copyright\r
11 * notice, this list of conditions and the following disclaimer.\r
12 * 2. Redistributions in binary form must reproduce the above copyright\r
13 * notice, this list of conditions and the following disclaimer in the\r
14 * documentation and/or other materials provided with the distribution.\r
15 *\r
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r
26 * SUCH DAMAGE.\r
27 *\r
28 * $Citrus$\r
29 */\r
30#include <LibConfig.h>\r
31#include <sys/EfiCdefs.h>\r
32#if defined(LIBC_SCCS) && !defined(lint)\r
33__RCSID("$NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp $");\r
34#endif /* LIBC_SCCS and not lint */\r
35\r
36#include <assert.h>\r
37#include <errno.h>\r
38#include <limits.h>\r
39#include <stdio.h>\r
40#include <wchar.h>\r
41#include "reentrant.h"\r
42#include "local.h"\r
43#include "fvwrite.h"\r
44\r
45wint_t\r
46__fputwc_unlock(wchar_t wc, FILE *fp)\r
47{\r
48 struct wchar_io_data *wcio;\r
49 mbstate_t *st;\r
50 size_t size;\r
51 char buf[MB_LEN_MAX];\r
52 struct __suio uio;\r
53 struct __siov iov;\r
54\r
55 _DIAGASSERT(fp != NULL);\r
56\r
57 /* LINTED we don't play with buf */\r
58 iov.iov_base = (void *)buf;\r
59 uio.uio_iov = &iov;\r
60 uio.uio_iovcnt = 1;\r
61\r
62 _SET_ORIENTATION(fp, 1);\r
63 wcio = WCIO_GET(fp);\r
64 if (wcio == 0) {\r
65 errno = ENOMEM;\r
66 return WEOF;\r
67 }\r
68\r
69 wcio->wcio_ungetwc_inbuf = 0;\r
70 st = &wcio->wcio_mbstate_out;\r
71\r
72 size = wcrtomb(buf, wc, st);\r
73 if (size == (size_t)-1) {\r
74 errno = EILSEQ;\r
75 return WEOF;\r
76 }\r
77\r
78 _DIAGASSERT(size != 0);\r
79\r
80 uio.uio_resid = (int)(iov.iov_len = size);\r
81 if (__sfvwrite(fp, &uio)) {\r
82 return WEOF;\r
83 }\r
84\r
85 return (wint_t)wc;\r
86}\r
87\r
88wint_t\r
89fputwc(wchar_t wc, FILE *fp)\r
90{\r
91 wint_t r;\r
92\r
93 _DIAGASSERT(fp != NULL);\r
94\r
95 FLOCKFILE(fp);\r
96 r = __fputwc_unlock(wc, fp);\r
97 FUNLOCKFILE(fp);\r
98\r
99 return (r);\r
100}\r