111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert//===------------------------ iostream.cpp --------------------------------===// 211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// 311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// The LLVM Compiler Infrastructure 411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// 511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// This file is dual licensed under the MIT and the University of Illinois Open 611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// Source Licenses. See LICENSE.TXT for details. 711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert// 811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert//===----------------------------------------------------------------------===// 911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 1011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#include "__std_stream" 1111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#include "string" 1211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert#include "new" 1311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 1411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_LIBCPP_BEGIN_NAMESPACE_STD 1511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 1611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertstatic mbstate_t state_types[6] = {}; 1711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 1811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin [sizeof(__stdinbuf <char>)]; 1911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)]; 2011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)]; 2111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin [sizeof(__stdinbuf <wchar_t>)]; 2211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)]; 2311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)]; 2411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 2511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (istream) _LIBCPP_FUNC_VIS char cin [sizeof(istream)]; 2611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cout[sizeof(ostream)]; 2711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)]; 2811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (ostream) _LIBCPP_FUNC_VIS char clog[sizeof(ostream)]; 2911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin [sizeof(wistream)]; 3011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)]; 3111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)]; 3211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)]; 3311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3411cd02dfb91661c65134cac258cf5924270e9d2Dan Albertios_base::Init __start_std_streams; 3511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 3611cd02dfb91661c65134cac258cf5924270e9d2Dan Albertios_base::Init::Init() 3711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert{ 3811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin, state_types+0) ); 3911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, state_types+1)); 4011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, state_types+2)); 4111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert ::new(clog) ostream(cerr_ptr->rdbuf()); 4211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert cin_ptr->tie(cout_ptr); 4311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert _VSTD::unitbuf(*cerr_ptr); 4411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert cerr_ptr->tie(cout_ptr); 4511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 4611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin, state_types+3) ); 4711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, state_types+4)); 4811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, state_types+5)); 4911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert ::new(wclog) wostream(wcerr_ptr->rdbuf()); 5011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert wcin_ptr->tie(wcout_ptr); 5111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert _VSTD::unitbuf(*wcerr_ptr); 5211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert wcerr_ptr->tie(wcout_ptr); 5311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} 5411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 5511cd02dfb91661c65134cac258cf5924270e9d2Dan Albertios_base::Init::~Init() 5611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert{ 5711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert ostream* cout_ptr = reinterpret_cast<ostream*>(cout); 5811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert ostream* clog_ptr = reinterpret_cast<ostream*>(clog); 5911cd02dfb91661c65134cac258cf5924270e9d2Dan Albert cout_ptr->flush(); 6011cd02dfb91661c65134cac258cf5924270e9d2Dan Albert clog_ptr->flush(); 6111cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 6211cd02dfb91661c65134cac258cf5924270e9d2Dan Albert wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout); 6311cd02dfb91661c65134cac258cf5924270e9d2Dan Albert wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog); 6411cd02dfb91661c65134cac258cf5924270e9d2Dan Albert wcout_ptr->flush(); 6511cd02dfb91661c65134cac258cf5924270e9d2Dan Albert wclog_ptr->flush(); 6611cd02dfb91661c65134cac258cf5924270e9d2Dan Albert} 6711cd02dfb91661c65134cac258cf5924270e9d2Dan Albert 6811cd02dfb91661c65134cac258cf5924270e9d2Dan Albert_LIBCPP_END_NAMESPACE_STD 69