]>
Commit | Line | Data |
---|---|---|
53e1e5c6 | 1 | /*\r |
a7a8363d | 2 | Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r |
53e1e5c6 | 3 | This program and the accompanying materials are licensed and made available\r |
4 | under the terms and conditions of the BSD License that accompanies this\r | |
5 | distribution. The full text of the license may be found at\r | |
6 | http://opensource.org/licenses/bsd-license.\r | |
7 | \r | |
8 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
9 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
2aa62f2b | 10 | \r |
2aa62f2b | 11 | * Copyright (c)2001 Citrus Project,\r |
12 | * All rights reserved.\r | |
13 | *\r | |
14 | * Redistribution and use in source and binary forms, with or without\r | |
15 | * modification, are permitted provided that the following conditions\r | |
16 | * are met:\r | |
17 | * 1. Redistributions of source code must retain the above copyright\r | |
18 | * notice, this list of conditions and the following disclaimer.\r | |
19 | * 2. Redistributions in binary form must reproduce the above copyright\r | |
20 | * notice, this list of conditions and the following disclaimer in the\r | |
21 | * documentation and/or other materials provided with the distribution.\r | |
22 | *\r | |
23 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND\r | |
24 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\r | |
25 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\r | |
26 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE\r | |
27 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\r | |
28 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS\r | |
29 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r | |
30 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT\r | |
31 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY\r | |
32 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF\r | |
33 | * SUCH DAMAGE.\r | |
34 | *\r | |
35 | * $Citrus$\r | |
53e1e5c6 | 36 | \r |
37 | NetBSD: fputwc.c,v 1.4 2005/06/12 05:21:27 lukem Exp\r | |
38 | */\r | |
2aa62f2b | 39 | #include <LibConfig.h>\r |
40 | #include <sys/EfiCdefs.h>\r | |
2aa62f2b | 41 | \r |
42 | #include <assert.h>\r | |
43 | #include <errno.h>\r | |
44 | #include <limits.h>\r | |
45 | #include <stdio.h>\r | |
46 | #include <wchar.h>\r | |
47 | #include "reentrant.h"\r | |
48 | #include "local.h"\r | |
49 | #include "fvwrite.h"\r | |
50 | \r | |
51 | wint_t\r | |
52 | __fputwc_unlock(wchar_t wc, FILE *fp)\r | |
53 | {\r | |
54 | struct wchar_io_data *wcio;\r | |
55 | mbstate_t *st;\r | |
56 | size_t size;\r | |
57 | char buf[MB_LEN_MAX];\r | |
58 | struct __suio uio;\r | |
59 | struct __siov iov;\r | |
60 | \r | |
61 | _DIAGASSERT(fp != NULL);\r | |
53e1e5c6 | 62 | if(fp == NULL) {\r |
63 | errno = EINVAL;\r | |
64 | return (WEOF);\r | |
65 | }\r | |
2aa62f2b | 66 | \r |
67 | /* LINTED we don't play with buf */\r | |
68 | iov.iov_base = (void *)buf;\r | |
69 | uio.uio_iov = &iov;\r | |
70 | uio.uio_iovcnt = 1;\r | |
71 | \r | |
72 | _SET_ORIENTATION(fp, 1);\r | |
73 | wcio = WCIO_GET(fp);\r | |
74 | if (wcio == 0) {\r | |
75 | errno = ENOMEM;\r | |
76 | return WEOF;\r | |
77 | }\r | |
78 | \r | |
79 | wcio->wcio_ungetwc_inbuf = 0;\r | |
80 | st = &wcio->wcio_mbstate_out;\r | |
81 | \r | |
82 | size = wcrtomb(buf, wc, st);\r | |
83 | if (size == (size_t)-1) {\r | |
2aa62f2b | 84 | return WEOF;\r |
85 | }\r | |
86 | \r | |
87 | _DIAGASSERT(size != 0);\r | |
88 | \r | |
89 | uio.uio_resid = (int)(iov.iov_len = size);\r | |
90 | if (__sfvwrite(fp, &uio)) {\r | |
91 | return WEOF;\r | |
92 | }\r | |
93 | \r | |
94 | return (wint_t)wc;\r | |
95 | }\r | |
96 | \r | |
97 | wint_t\r | |
98 | fputwc(wchar_t wc, FILE *fp)\r | |
99 | {\r | |
100 | wint_t r;\r | |
101 | \r | |
102 | _DIAGASSERT(fp != NULL);\r | |
53e1e5c6 | 103 | if(fp == NULL) {\r |
104 | errno = EINVAL;\r | |
105 | return (WEOF);\r | |
106 | }\r | |
2aa62f2b | 107 | \r |
108 | FLOCKFILE(fp);\r | |
109 | r = __fputwc_unlock(wc, fp);\r | |
110 | FUNLOCKFILE(fp);\r | |
111 | \r | |
112 | return (r);\r | |
113 | }\r |