Back to index

glibc  2.9
oldstdfiles.c
Go to the documentation of this file.
00001 /* Copyright (C) 1993,94,96,97,99,2000,2002,2004 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.
00018 
00019    As a special exception, if you link the code in this file with
00020    files compiled with a GNU compiler to produce an executable,
00021    that does not cause the resulting executable to be covered by
00022    the GNU Lesser General Public License.  This exception does not
00023    however invalidate any other reasons why the executable file
00024    might be covered by the GNU Lesser General Public License.
00025    This exception applies to code released by its copyright holders
00026    in files containing the exception.  */
00027 
00028 #include <shlib-compat.h>
00029 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
00030 
00031 /* This file provides definitions of _IO_stdin, _IO_stdout, and _IO_stderr
00032    for C code.  Compare stdstreams.cc.
00033    (The difference is that here the vtable field is set to 0,
00034    so the objects defined are not valid C++ objects.  On the other
00035    hand, we don't need a C++ compiler to build this file.) */
00036 
00037 #define _IO_USE_OLD_IO_FILE
00038 #include "libioP.h"
00039 
00040 #ifdef _IO_MTSAFE_IO
00041 #define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
00042   static _IO_lock_t _IO_stdfile_##FD##_lock = _IO_lock_initializer; \
00043   struct _IO_FILE_plus NAME \
00044     = {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), &_IO_old_file_jumps};
00045 #else
00046 #define DEF_STDFILE(NAME, FD, CHAIN, FLAGS) \
00047   struct _IO_FILE_plus NAME \
00048     = {FILEBUF_LITERAL(CHAIN, FLAGS, FD, NULL), &_IO_old_file_jumps};
00049 #endif
00050 
00051 DEF_STDFILE(_IO_stdin_, 0, 0, _IO_NO_WRITES);
00052 DEF_STDFILE(_IO_stdout_, 1, &_IO_stdin_, _IO_NO_READS);
00053 DEF_STDFILE(_IO_stderr_, 2, &_IO_stdout_, _IO_NO_READS+_IO_UNBUFFERED);
00054 
00055 #if defined __GNUC__ && __GNUC__ >= 2
00056 
00057 #include <stdio.h>
00058 
00059 extern const int _IO_stdin_used;
00060 weak_extern (_IO_stdin_used);
00061 
00062 #undef stdin
00063 #undef stdout
00064 #undef stderr
00065 
00066 extern FILE *stdin;
00067 extern FILE *stdout;
00068 extern FILE *stderr;
00069 
00070 static void _IO_check_libio (void) __THROW __attribute__ ((constructor));
00071 
00072 /* This function determines which shared C library the application
00073    was linked against. We then set up the stdin/stdout/stderr and
00074    _IO_list_all accordingly. */
00075 
00076 static void
00077 _IO_check_libio ()
00078 {
00079   if (&_IO_stdin_used == NULL)
00080     {
00081       /* We are using the old one. */
00082       _IO_stdin = stdin = (_IO_FILE *) &_IO_stdin_;
00083       _IO_stdout = stdout = (_IO_FILE *) &_IO_stdout_;
00084       _IO_stderr = stderr = (_IO_FILE *) &_IO_stderr_;
00085       INTUSE(_IO_list_all) = &_IO_stderr_;
00086       _IO_stdin->_vtable_offset = _IO_stdout->_vtable_offset =
00087        _IO_stderr->_vtable_offset = stdin->_vtable_offset =
00088        stdout->_vtable_offset = stderr->_vtable_offset =
00089        ((int) sizeof (struct _IO_FILE)
00090         - (int) sizeof (struct _IO_FILE_complete));
00091     }
00092 }
00093 
00094 #endif
00095 
00096 #endif