]> git.proxmox.com Git - mirror_edk2.git/blame - StdLib/LibC/Stdio/fwide.c
EmbeddedPkg: Extend NvVarStoreFormattedLib LIBRARY_CLASS
[mirror_edk2.git] / StdLib / LibC / Stdio / fwide.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)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: fwide.c,v 1.3 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
53e1e5c6 43#include <errno.h>\r
2aa62f2b 44#include <stdio.h>\r
45#include <wchar.h>\r
46#include "reentrant.h"\r
47#include "local.h"\r
48\r
49int\r
50fwide(FILE *fp, int mode)\r
51{\r
52 struct wchar_io_data *wcio;\r
53\r
54 _DIAGASSERT(fp != NULL);\r
53e1e5c6 55 if(fp == NULL) {\r
56 errno = EINVAL;\r
57 return (0);\r
58 }\r
2aa62f2b 59\r
60 /*\r
61 * this implementation use only -1, 0, 1\r
62 * for mode value.\r
63 * (we don't need to do this, but\r
64 * this can make things simpler.)\r
65 */\r
66 if (mode > 0)\r
67 mode = 1;\r
68 else if (mode < 0)\r
69 mode = -1;\r
70\r
71 FLOCKFILE(fp);\r
72 wcio = WCIO_GET(fp);\r
73 if (!wcio)\r
74 return 0; /* XXX */\r
75\r
76 if (wcio->wcio_mode == 0 && mode != 0)\r
77 wcio->wcio_mode = mode;\r
78 else\r
79 mode = wcio->wcio_mode;\r
80 FUNLOCKFILE(fp);\r
81\r
82 return mode;\r
83}\r