1bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===------------------------ iostream.cpp --------------------------------===//
2bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
3f5256e16dfc425c1d466f6308d4026d529ce9e0bHoward Hinnant//                     The LLVM Compiler Infrastructure
4bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
5b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// This file is dual licensed under the MIT and the University of Illinois Open
6b64f8b07c104c6cc986570ac8ee0ed16a9f23976Howard Hinnant// Source Licenses. See LICENSE.TXT for details.
7bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//
8bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant//===----------------------------------------------------------------------===//
9bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
10bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "__std_stream"
11bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant#include "string"
121378397721435d2737ab494908918bfe88882789Howard Hinnant#include "new"
13bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
14bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant_LIBCPP_BEGIN_NAMESPACE_STD
15bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
16903439f7359b1bfaecb59134bbe6bc869501e537Howard Hinnantstatic mbstate_t state_types[6] = {};
17903439f7359b1bfaecb59134bbe6bc869501e537Howard Hinnant
18cbdd0896d3629a17d11be4078347e085b26099f5Howard Hinnant_ALIGNAS_TYPE (__stdinbuf<char> ) static char __cin [sizeof(__stdinbuf <char>)];
19cbdd0896d3629a17d11be4078347e085b26099f5Howard Hinnant_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)];
20cbdd0896d3629a17d11be4078347e085b26099f5Howard Hinnant_ALIGNAS_TYPE (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)];
21cbdd0896d3629a17d11be4078347e085b26099f5Howard Hinnant_ALIGNAS_TYPE (__stdinbuf<wchar_t> ) static char __wcin [sizeof(__stdinbuf <wchar_t>)];
22cbdd0896d3629a17d11be4078347e085b26099f5Howard Hinnant_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)];
23cbdd0896d3629a17d11be4078347e085b26099f5Howard Hinnant_ALIGNAS_TYPE (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)];
241378397721435d2737ab494908918bfe88882789Howard Hinnant
250f678bd69ef6428e6c75ae1b43fcf1543df63cdaHoward Hinnant_ALIGNAS_TYPE (istream)  _LIBCPP_FUNC_VIS char cin [sizeof(istream)];
260f678bd69ef6428e6c75ae1b43fcf1543df63cdaHoward Hinnant_ALIGNAS_TYPE (ostream)  _LIBCPP_FUNC_VIS char cout[sizeof(ostream)];
270f678bd69ef6428e6c75ae1b43fcf1543df63cdaHoward Hinnant_ALIGNAS_TYPE (ostream)  _LIBCPP_FUNC_VIS char cerr[sizeof(ostream)];
280f678bd69ef6428e6c75ae1b43fcf1543df63cdaHoward Hinnant_ALIGNAS_TYPE (ostream)  _LIBCPP_FUNC_VIS char clog[sizeof(ostream)];
290f678bd69ef6428e6c75ae1b43fcf1543df63cdaHoward Hinnant_ALIGNAS_TYPE (wistream) _LIBCPP_FUNC_VIS char wcin [sizeof(wistream)];
300f678bd69ef6428e6c75ae1b43fcf1543df63cdaHoward Hinnant_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcout[sizeof(wostream)];
310f678bd69ef6428e6c75ae1b43fcf1543df63cdaHoward Hinnant_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wcerr[sizeof(wostream)];
320f678bd69ef6428e6c75ae1b43fcf1543df63cdaHoward Hinnant_ALIGNAS_TYPE (wostream) _LIBCPP_FUNC_VIS char wclog[sizeof(wostream)];
33bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
34bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantios_base::Init __start_std_streams;
35bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
36bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantios_base::Init::Init()
37bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
38903439f7359b1bfaecb59134bbe6bc869501e537Howard Hinnant    istream* cin_ptr  = ::new(cin)  istream(::new(__cin)  __stdinbuf <char>(stdin, state_types+0) );
39903439f7359b1bfaecb59134bbe6bc869501e537Howard Hinnant    ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout, state_types+1));
40903439f7359b1bfaecb59134bbe6bc869501e537Howard Hinnant    ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr, state_types+2));
411378397721435d2737ab494908918bfe88882789Howard Hinnant                        ::new(clog) ostream(cerr_ptr->rdbuf());
421378397721435d2737ab494908918bfe88882789Howard Hinnant    cin_ptr->tie(cout_ptr);
431378397721435d2737ab494908918bfe88882789Howard Hinnant    _VSTD::unitbuf(*cerr_ptr);
441378397721435d2737ab494908918bfe88882789Howard Hinnant    cerr_ptr->tie(cout_ptr);
45bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
46903439f7359b1bfaecb59134bbe6bc869501e537Howard Hinnant    wistream* wcin_ptr  = ::new(wcin)  wistream(::new(__wcin)  __stdinbuf <wchar_t>(stdin, state_types+3) );
47903439f7359b1bfaecb59134bbe6bc869501e537Howard Hinnant    wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout, state_types+4));
48903439f7359b1bfaecb59134bbe6bc869501e537Howard Hinnant    wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr, state_types+5));
491378397721435d2737ab494908918bfe88882789Howard Hinnant                          ::new(wclog) wostream(wcerr_ptr->rdbuf());
501378397721435d2737ab494908918bfe88882789Howard Hinnant    wcin_ptr->tie(wcout_ptr);
511378397721435d2737ab494908918bfe88882789Howard Hinnant    _VSTD::unitbuf(*wcerr_ptr);
521378397721435d2737ab494908918bfe88882789Howard Hinnant    wcerr_ptr->tie(wcout_ptr);
53bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
54bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
55bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnantios_base::Init::~Init()
56bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant{
57d3b5b6b9f4656d94628ed33e50a5eeee3b7fa1c3Joerg Sonnenberger    ostream* cout_ptr = reinterpret_cast<ostream*>(cout);
58d3b5b6b9f4656d94628ed33e50a5eeee3b7fa1c3Joerg Sonnenberger    ostream* clog_ptr = reinterpret_cast<ostream*>(clog);
591378397721435d2737ab494908918bfe88882789Howard Hinnant    cout_ptr->flush();
601378397721435d2737ab494908918bfe88882789Howard Hinnant    clog_ptr->flush();
61bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
62d3b5b6b9f4656d94628ed33e50a5eeee3b7fa1c3Joerg Sonnenberger    wostream* wcout_ptr = reinterpret_cast<wostream*>(wcout);
63d3b5b6b9f4656d94628ed33e50a5eeee3b7fa1c3Joerg Sonnenberger    wostream* wclog_ptr = reinterpret_cast<wostream*>(wclog);
641378397721435d2737ab494908918bfe88882789Howard Hinnant    wcout_ptr->flush();
651378397721435d2737ab494908918bfe88882789Howard Hinnant    wclog_ptr->flush();
66bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant}
67bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant
68bc8d3f97eb5c958007f2713238472e0c1c8fe02Howard Hinnant_LIBCPP_END_NAMESPACE_STD
69