]>
git.proxmox.com Git - mirror_edk2.git/blob - StdLib/LibC/Stdio/wsetup.c
2 Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
3 This program and the accompanying materials are licensed and made available
4 under the terms and conditions of the BSD License that accompanies this
5 distribution. The full text of the license may be found at
6 http://opensource.org/licenses/bsd-license.
8 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
9 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
11 * Copyright (c) 1990, 1993
12 * The Regents of the University of California. All rights reserved.
14 * This code is derived from software contributed to Berkeley by
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. Neither the name of the University nor the names of its contributors
26 * may be used to endorse or promote products derived from this software
27 * without specific prior written permission.
29 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 NetBSD: wsetup.c,v 1.11 2003/08/07 16:43:35 agc Exp
42 wsetup.c 8.1 (Berkeley) 6/4/93
44 #include <LibConfig.h>
45 #include <sys/EfiCdefs.h>
51 #include "reentrant.h"
55 * Various output routines call wsetup to be sure it is safe to write,
56 * because either _flags does not include __SWR, or _buf is NULL.
57 * _wsetup returns 0 if OK to write, nonzero otherwise.
63 _DIAGASSERT(fp
!= NULL
);
69 /* make sure stdio is set up */
74 * If we are not writing, we had better be reading and writing.
76 if ((fp
->_flags
& __SWR
) == 0) {
77 if ((fp
->_flags
& __SRW
) == 0)
79 if (fp
->_flags
& __SRD
) {
80 /* clobber any ungetc data */
83 fp
->_flags
&= ~(__SRD
|__SEOF
);
85 fp
->_p
= fp
->_bf
._base
;
91 * Make a buffer if necessary, then set _w.
93 if (fp
->_bf
._base
== NULL
)
95 if (fp
->_flags
& __SLBF
) {
97 * It is line buffered, so make _lbfsize be -_bufsize
98 * for the putc() macro. We will change _lbfsize back
99 * to 0 whenever we turn off __SWR.
102 fp
->_lbfsize
= -fp
->_bf
._size
;
104 fp
->_w
= fp
->_flags
& __SNBF
? 0 : fp
->_bf
._size
;