]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/oldstdfiles.c
Update copyright notices with scripts/update-copyrights
[thirdparty/glibc.git] / libio / oldstdfiles.c
CommitLineData
d4697bc9 1/* Copyright (C) 1993-2014 Free Software Foundation, Inc.
41bdb6e2 2 This file is part of the GNU C Library.
1ea89a40 3
41bdb6e2
AJ
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
1ea89a40 8
41bdb6e2
AJ
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
1ea89a40 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 12 Lesser General Public License for more details.
1ea89a40 13
41bdb6e2 14 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>.
1ea89a40 17
41bdb6e2
AJ
18 As a special exception, if you link the code in this file with
19 files compiled with a GNU compiler to produce an executable,
20 that does not cause the resulting executable to be covered by
21 the GNU Lesser General Public License. This exception does not
22 however invalidate any other reasons why the executable file
23 might be covered by the GNU Lesser General Public License.
24 This exception applies to code released by its copyright holders
25 in files containing the exception. */
1ea89a40 26
16710d58
RM
27#include <shlib-compat.h>
28#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
1ea89a40
UD
29
30/* This file provides definitions of _IO_stdin, _IO_stdout, and _IO_stderr
31 for C code. Compare stdstreams.cc.
32 (The difference is that here the vtable field is set to 0,
33 so the objects defined are not valid C++ objects. On the other
34 hand, we don't need a C++ compiler to build this file.) */
35
bd355af0 36#define _IO_USE_OLD_IO_FILE
1ea89a40
UD
37#include "libioP.h"
38
39#ifdef _IO_MTSAFE_IO
bd355af0 40#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
1ea89a40 41 static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
bd355af0 42 struct _IO_FILE_plus NAME \
d64b6ad0 43 = {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), &_IO_old_file_jumps};
1ea89a40 44#else
bd355af0
UD
45#define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
46 struct _IO_FILE_plus NAME \
d64b6ad0 47 = {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), &_IO_old_file_jumps};
1ea89a40
UD
48#endif
49
bd355af0 50DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES);
2ca8b1ee
GM
51DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_, _IO_NO_READS);
52DEF_STDFILE(_IO_stderr_, 2, &_IO_stdout_, _IO_NO_READS+_IO_UNBUFFERED);
1ea89a40 53
6973fc01
UD
54#if defined __GNUC__ && __GNUC__ >= 2
55
56#include <stdio.h>
57
9c4c0024 58extern const int _IO_stdin_used;
6973fc01
UD
59weak_extern (_IO_stdin_used);
60
61#undef stdin
62#undef stdout
63#undef stderr
64
65extern FILE *stdin;
66extern FILE *stdout;
67extern FILE *stderr;
68
79937577 69static void _IO_check_libio (void) __THROW __attribute__ ((constructor));
6973fc01
UD
70
71/* This function determines which shared C library the application
72 was linked against. We then set up the stdin/stdout/stderr and
73 _IO_list_all accordingly. */
74
75static void
60d2f8f3 76_IO_check_libio (void)
6973fc01
UD
77{
78 if (&_IO_stdin_used == NULL)
79 {
80 /* We are using the old one. */
2ca8b1ee
GM
81 _IO_stdin = stdin = (_IO_FILE *) &_IO_stdin_;
82 _IO_stdout = stdout = (_IO_FILE *) &_IO_stdout_;
83 _IO_stderr = stderr = (_IO_FILE *) &_IO_stderr_;
d18ea0c5 84 _IO_list_all = &_IO_stderr_;
bd355af0
UD
85 _IO_stdin->_vtable_offset = _IO_stdout->_vtable_offset =
86 _IO_stderr->_vtable_offset = stdin->_vtable_offset =
87 stdout->_vtable_offset = stderr->_vtable_offset =
88 ((int) sizeof (struct _IO_FILE)
89 - (int) sizeof (struct _IO_FILE_complete));
6973fc01
UD
90 }
91}
92
f2ea0f5b 93#endif
16710d58
RM
94
95#endif