1 /* Copyright (C) 1993,94,96,97,99,2000 Free Software Foundation, Inc.
2 This file is part of the GNU IO Library.
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2, or (at
7 your option) any later version.
9 This library is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this library; see the file COPYING. If not, write to
16 the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 As a special exception, if you link this library with files
20 compiled with a GNU compiler to produce an executable, this does
21 not cause the resulting executable to be covered by the GNU General
22 Public License. This exception does not however invalidate any
23 other reasons why the executable file might be covered by the GNU
24 General Public License. */
26 #include <shlib-compat.h>
27 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
29 /* This file provides definitions of _IO_stdin, _IO_stdout, and _IO_stderr
30 for C code. Compare stdstreams.cc.
31 (The difference is that here the vtable field is set to 0,
32 so the objects defined are not valid C++ objects. On the other
33 hand, we don't need a C++ compiler to build this file.) */
35 #define _IO_USE_OLD_IO_FILE
39 #define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
40 static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
41 struct _IO_FILE_plus NAME \
42 = {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), &_IO_old_file_jumps};
44 #define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
45 static struct _IO_wide_data _IO_wide_data_##FD; \
46 struct _IO_FILE_plus NAME \
47 = {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), &_IO_old_file_jumps};
50 DEF_STDFILE(_IO_stdin_
, 0, 0, _IO_NO_WRITES
);
51 DEF_STDFILE(_IO_stdout_
, 1, &_IO_stdin_
, _IO_NO_READS
);
52 DEF_STDFILE(_IO_stderr_
, 2, &_IO_stdout_
, _IO_NO_READS
+_IO_UNBUFFERED
);
54 #if defined __GNUC__ && __GNUC__ >= 2
58 extern const int _IO_stdin_used
;
59 weak_extern (_IO_stdin_used
);
69 extern struct _IO_FILE_plus
*_IO_list_all
;
71 static void _IO_check_libio
__P ((void)) __attribute__ ((constructor
));
73 /* This function determines which shared C library the application
74 was linked against. We then set up the stdin/stdout/stderr and
75 _IO_list_all accordingly. */
80 if (&_IO_stdin_used
== NULL
)
82 /* We are using the old one. */
83 _IO_stdin
= stdin
= (_IO_FILE
*) &_IO_stdin_
;
84 _IO_stdout
= stdout
= (_IO_FILE
*) &_IO_stdout_
;
85 _IO_stderr
= stderr
= (_IO_FILE
*) &_IO_stderr_
;
86 _IO_list_all
= &_IO_stderr_
;
87 _IO_stdin
->_vtable_offset
= _IO_stdout
->_vtable_offset
=
88 _IO_stderr
->_vtable_offset
= stdin
->_vtable_offset
=
89 stdout
->_vtable_offset
= stderr
->_vtable_offset
=
90 ((int) sizeof (struct _IO_FILE
)
91 - (int) sizeof (struct _IO_FILE_complete
));