Update.
[glibc.git] / libio / oldstdfiles.c
blob7781a17449f4ca7d4228a81e820da4ba3b2bd206
1 /* Copyright (C) 1993, 1994, 1996, 1997 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,
17 MA 02111-1307, USA.
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. */
27 /* This file provides definitions of _IO_stdin, _IO_stdout, and _IO_stderr
28 for C code. Compare stdstreams.cc.
29 (The difference is that here the vtable field is set to 0,
30 so the objects defined are not valid C++ objects. On the other
31 hand, we don't need a C++ compiler to build this file.) */
33 #define _IO_USE_OLD_IO_FILE
34 #include "libioP.h"
36 #ifdef _IO_MTSAFE_IO
37 #define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
38 static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
39 struct _IO_FILE_plus NAME \
40 = {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_old_file_jumps};
41 #else
42 #define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
43 struct _IO_FILE_plus NAME \
44 = {FILEBUF_LITERAL(CHAIN, FLAGS, FD), &_IO_old_file_jumps};
45 #endif
47 DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES);
48 DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_.file, _IO_NO_READS);
49 DEF_STDFILE(_IO_stderr_, 2, &_IO_stdout_.file,
50 _IO_NO_READS+_IO_UNBUFFERED);
52 #if defined __GNUC__ && __GNUC__ >= 2
54 #include <stdio.h>
56 extern const int _IO_stdin_used;
57 weak_extern (_IO_stdin_used);
59 #undef stdin
60 #undef stdout
61 #undef stderr
63 extern FILE *stdin;
64 extern FILE *stdout;
65 extern FILE *stderr;
67 extern FILE *_IO_list_all;
69 static void _IO_check_libio __P ((void)) __attribute__ ((constructor));
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. */
75 static void
76 _IO_check_libio ()
78 if (&_IO_stdin_used == NULL)
80 /* We are using the old one. */
81 _IO_stdin = stdin = &_IO_stdin_.file;
82 _IO_stdout = stdout = &_IO_stdout_.file;
83 _IO_stderr = stderr = _IO_list_all = &_IO_stderr_.file;
84 _IO_stdin->_vtable_offset = _IO_stdout->_vtable_offset =
85 _IO_stderr->_vtable_offset = stdin->_vtable_offset =
86 stdout->_vtable_offset = stderr->_vtable_offset =
87 ((int) sizeof (struct _IO_FILE)
88 - (int) sizeof (struct _IO_FILE_complete));
92 #endif