Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 1 | //===------------------------ iostream.cpp --------------------------------===// |
| 2 | // |
Howard Hinnant | c566dc3 | 2010-05-11 21:36:01 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 4 | // |
Howard Hinnant | ee11c31 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | #include "__std_stream" |
| 11 | #include "string" |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 12 | #include "new" |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 13 | |
| 14 | _LIBCPP_BEGIN_NAMESPACE_STD |
| 15 | |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 16 | alignas (__stdinbuf<char> ) static char __cin [sizeof(__stdinbuf <char>)]; |
| 17 | alignas (__stdoutbuf<char>) static char __cout[sizeof(__stdoutbuf<char>)]; |
| 18 | alignas (__stdoutbuf<char>) static char __cerr[sizeof(__stdoutbuf<char>)]; |
| 19 | alignas (__stdinbuf<wchar_t> ) static char __wcin [sizeof(__stdinbuf <wchar_t>)]; |
| 20 | alignas (__stdoutbuf<wchar_t>) static char __wcout[sizeof(__stdoutbuf<wchar_t>)]; |
| 21 | alignas (__stdoutbuf<wchar_t>) static char __wcerr[sizeof(__stdoutbuf<wchar_t>)]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 22 | |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 23 | alignas (istream) char cin [sizeof(istream)]; |
| 24 | alignas (ostream) char cout[sizeof(ostream)]; |
| 25 | alignas (ostream) char cerr[sizeof(ostream)]; |
| 26 | alignas (ostream) char clog[sizeof(ostream)]; |
| 27 | alignas (wistream) char wcin [sizeof(wistream)]; |
| 28 | alignas (wostream) char wcout[sizeof(wostream)]; |
| 29 | alignas (wostream) char wcerr[sizeof(wostream)]; |
| 30 | alignas (wostream) char wclog[sizeof(wostream)]; |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 31 | |
| 32 | ios_base::Init __start_std_streams; |
| 33 | |
| 34 | ios_base::Init::Init() |
| 35 | { |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 36 | istream* cin_ptr = ::new(cin) istream(::new(__cin) __stdinbuf <char>(stdin) ); |
| 37 | ostream* cout_ptr = ::new(cout) ostream(::new(__cout) __stdoutbuf<char>(stdout)); |
| 38 | ostream* cerr_ptr = ::new(cerr) ostream(::new(__cerr) __stdoutbuf<char>(stderr)); |
| 39 | ::new(clog) ostream(cerr_ptr->rdbuf()); |
| 40 | cin_ptr->tie(cout_ptr); |
| 41 | _VSTD::unitbuf(*cerr_ptr); |
| 42 | cerr_ptr->tie(cout_ptr); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 43 | |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 44 | wistream* wcin_ptr = ::new(wcin) wistream(::new(__wcin) __stdinbuf <wchar_t>(stdin) ); |
| 45 | wostream* wcout_ptr = ::new(wcout) wostream(::new(__wcout) __stdoutbuf<wchar_t>(stdout)); |
| 46 | wostream* wcerr_ptr = ::new(wcerr) wostream(::new(__wcerr) __stdoutbuf<wchar_t>(stderr)); |
| 47 | ::new(wclog) wostream(wcerr_ptr->rdbuf()); |
| 48 | wcin_ptr->tie(wcout_ptr); |
| 49 | _VSTD::unitbuf(*wcerr_ptr); |
| 50 | wcerr_ptr->tie(wcout_ptr); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | ios_base::Init::~Init() |
| 54 | { |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 55 | ostream* cout_ptr = (ostream*)cout; |
| 56 | ostream* clog_ptr = (ostream*)clog; |
| 57 | cout_ptr->flush(); |
| 58 | clog_ptr->flush(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 59 | |
Howard Hinnant | 877c679 | 2012-03-16 15:13:51 +0000 | [diff] [blame] | 60 | wostream* wcout_ptr = (wostream*)wcout; |
| 61 | wostream* wclog_ptr = (wostream*)wclog; |
| 62 | wcout_ptr->flush(); |
| 63 | wclog_ptr->flush(); |
Howard Hinnant | c51e102 | 2010-05-11 19:42:16 +0000 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | _LIBCPP_END_NAMESPACE_STD |