]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/LibC/Stdio/fgetwc.c
StdLib: reinstate the use of va_arg() to handle long double arguments in vfscanf.
[mirror_edk2.git] / StdLib / LibC / Stdio / fgetwc.c
CommitLineData
2aa62f2b 1/*-\r
53e1e5c6 2 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
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
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
36\r
37 NetBSD: fgetwc.c,v 1.5 2006/07/03 17:06:36 tnozaki Exp\r
38 */\r
39#include <LibConfig.h>\r
40#include <sys/EfiCdefs.h>\r
41\r
42#include <assert.h>\r
43#include <errno.h>\r
44#include <stdio.h>\r
45#include <wchar.h>\r
46#include "reentrant.h"\r
47#include "local.h"\r
48\r
49wint_t\r
50__fgetwc_unlock(FILE *fp)\r
51{\r
52 struct wchar_io_data *wcio;\r
53 mbstate_t *st;\r
54 wchar_t wc;\r
55 size_t size;\r
56\r
57 _DIAGASSERT(fp != NULL);\r
53e1e5c6 58 if(fp == NULL) {\r
59 errno = ENOSTR;\r
60 return WEOF;\r
61 }\r
2aa62f2b 62\r
63 _SET_ORIENTATION(fp, 1);\r
64 wcio = WCIO_GET(fp);\r
65 if (wcio == 0) {\r
66 errno = ENOMEM;\r
67 return WEOF;\r
68 }\r
69\r
70 /* if there're ungetwc'ed wchars, use them */\r
71 if (wcio->wcio_ungetwc_inbuf) {\r
72 wc = wcio->wcio_ungetwc_buf[--wcio->wcio_ungetwc_inbuf];\r
73\r
74 return wc;\r
75 }\r
76\r
77 st = &wcio->wcio_mbstate_in;\r
78\r
79 do {\r
80 char c;\r
81 int ch = __sgetc(fp);\r
82\r
83 if (ch == EOF) {\r
84 return WEOF;\r
85 }\r
86\r
87 c = (char)ch;\r
88 size = mbrtowc(&wc, &c, 1, st);\r
89 if (size == (size_t)-1) {\r
90 errno = EILSEQ;\r
91 fp->_flags |= __SERR;\r
92 return WEOF;\r
93 }\r
94 } while (size == (size_t)-2);\r
95\r
96 _DIAGASSERT(size == 1);\r
97\r
98 return wc;\r
99}\r
100\r
101wint_t\r
102fgetwc(FILE *fp)\r
103{\r
104 wint_t r;\r
105\r
106 _DIAGASSERT(fp != NULL);\r
53e1e5c6 107 if(fp == NULL) {\r
108 errno = EINVAL;\r
109 return (WEOF);\r
110 }\r
2aa62f2b 111\r
112 FLOCKFILE(fp);\r
113 r = __fgetwc_unlock(fp);\r
114 FUNLOCKFILE(fp);\r
115\r
116 return (r);\r
117}\r