]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/LibC/Stdio/fgetws.c
StdLib/LibC/Stdio: fix "missing braces around initializer"
[mirror_edk2.git] / StdLib / LibC / Stdio / fgetws.c
CommitLineData
53e1e5c6 1/*\r
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
2aa62f2b 10\r
2aa62f2b 11 * Copyright (c) 2002 Tim J. Robbins.\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 * Original version ID:\r
36 * FreeBSD: src/lib/libc/stdio/fgetws.c,v 1.4 2002/09/20 13:25:40 tjr Exp\r
53e1e5c6 37\r
38 $NetBSD: fgetws.c,v 1.2 2006/07/03 17:06:36 tnozaki Exp $\r
39*/\r
2aa62f2b 40#include <LibConfig.h>\r
41#include <sys/EfiCdefs.h>\r
2aa62f2b 42\r
43#include <assert.h>\r
44#include <errno.h>\r
45#include <stdio.h>\r
46#include <wchar.h>\r
47#include "reentrant.h"\r
48#include "local.h"\r
49\r
50wchar_t *\r
51fgetws(\r
52 wchar_t * __restrict ws,\r
53 int n,\r
54 FILE * __restrict fp\r
55 )\r
56{\r
57 wchar_t *wsp;\r
58 wint_t wc;\r
59\r
60 _DIAGASSERT(fp != NULL);\r
61 _DIAGASSERT(ws != NULL);\r
53e1e5c6 62 if(fp == NULL) {\r
63 errno = EINVAL;\r
64 return (NULL);\r
65 }\r
2aa62f2b 66\r
67 FLOCKFILE(fp);\r
68 _SET_ORIENTATION(fp, 1);\r
69\r
70 if (n <= 0) {\r
71 errno = EINVAL;\r
72 goto error;\r
73 }\r
74\r
75 wsp = ws;\r
76 while (n-- > 1) {\r
77 wc = __fgetwc_unlock(fp);\r
78 if (__sferror(fp) != 0)\r
79 goto error;\r
80 if (__sfeof(fp) != 0) {\r
81 if (wsp == ws) {\r
82 /* EOF/error, no characters read yet. */\r
83 goto error;\r
84 }\r
85 break;\r
86 }\r
87 *wsp++ = (wchar_t)wc;\r
88 if (wc == L'\n') {\r
89 break;\r
90 }\r
91 }\r
92\r
93 *wsp++ = L'\0';\r
94 FUNLOCKFILE(fp);\r
95\r
96 return (ws);\r
97\r
98error:\r
99 FUNLOCKFILE(fp);\r
100 return (NULL);\r
101}\r