1 //===------------------------ iostream.cpp --------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is dual licensed under the MIT and the University of Illinois Open
6 // Source Licenses. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "__std_stream"
14 _LIBCPP_BEGIN_NAMESPACE_STD
16 #ifndef _LIBCPP_HAS_NO_STDIN
17 _ALIGNAS_TYPE (istream
) _LIBCPP_FUNC_VIS
char cin
[sizeof(istream
)];
18 _ALIGNAS_TYPE (__stdinbuf
<char> ) static char __cin
[sizeof(__stdinbuf
<char>)];
19 static mbstate_t mb_cin
;
20 _ALIGNAS_TYPE (wistream
) _LIBCPP_FUNC_VIS
char wcin
[sizeof(wistream
)];
21 _ALIGNAS_TYPE (__stdinbuf
<wchar_t> ) static char __wcin
[sizeof(__stdinbuf
<wchar_t>)];
22 static mbstate_t mb_wcin
;
25 #ifndef _LIBCPP_HAS_NO_STDOUT
26 _ALIGNAS_TYPE (ostream
) _LIBCPP_FUNC_VIS
char cout
[sizeof(ostream
)];
27 _ALIGNAS_TYPE (__stdoutbuf
<char>) static char __cout
[sizeof(__stdoutbuf
<char>)];
28 static mbstate_t mb_cout
;
29 _ALIGNAS_TYPE (wostream
) _LIBCPP_FUNC_VIS
char wcout
[sizeof(wostream
)];
30 _ALIGNAS_TYPE (__stdoutbuf
<wchar_t>) static char __wcout
[sizeof(__stdoutbuf
<wchar_t>)];
31 static mbstate_t mb_wcout
;
34 _ALIGNAS_TYPE (ostream
) _LIBCPP_FUNC_VIS
char cerr
[sizeof(ostream
)];
35 _ALIGNAS_TYPE (__stdoutbuf
<char>) static char __cerr
[sizeof(__stdoutbuf
<char>)];
36 static mbstate_t mb_cerr
;
37 _ALIGNAS_TYPE (wostream
) _LIBCPP_FUNC_VIS
char wcerr
[sizeof(wostream
)];
38 _ALIGNAS_TYPE (__stdoutbuf
<wchar_t>) static char __wcerr
[sizeof(__stdoutbuf
<wchar_t>)];
39 static mbstate_t mb_wcerr
;
41 _ALIGNAS_TYPE (ostream
) _LIBCPP_FUNC_VIS
char clog
[sizeof(ostream
)];
42 _ALIGNAS_TYPE (wostream
) _LIBCPP_FUNC_VIS
char wclog
[sizeof(wostream
)];
44 ios_base::Init __start_std_streams
;
46 ios_base::Init::Init()
48 #ifndef _LIBCPP_HAS_NO_STDIN
49 istream
* cin_ptr
= ::new(cin
) istream(::new(__cin
) __stdinbuf
<char>(stdin
, &mb_cin
));
50 wistream
* wcin_ptr
= ::new(wcin
) wistream(::new(__wcin
) __stdinbuf
<wchar_t>(stdin
, &mb_wcin
));
52 #ifndef _LIBCPP_HAS_NO_STDOUT
53 ostream
* cout_ptr
= ::new(cout
) ostream(::new(__cout
) __stdoutbuf
<char>(stdout
, &mb_cout
));
54 wostream
* wcout_ptr
= ::new(wcout
) wostream(::new(__wcout
) __stdoutbuf
<wchar_t>(stdout
, &mb_wcout
));
56 ostream
* cerr_ptr
= ::new(cerr
) ostream(::new(__cerr
) __stdoutbuf
<char>(stderr
, &mb_cerr
));
57 ::new(clog
) ostream(cerr_ptr
->rdbuf());
58 wostream
* wcerr_ptr
= ::new(wcerr
) wostream(::new(__wcerr
) __stdoutbuf
<wchar_t>(stderr
, &mb_wcerr
));
59 ::new(wclog
) wostream(wcerr_ptr
->rdbuf());
61 #if !defined(_LIBCPP_HAS_NO_STDIN) && !defined(_LIBCPP_HAS_NO_STDOUT)
62 cin_ptr
->tie(cout_ptr
);
63 wcin_ptr
->tie(wcout_ptr
);
65 _VSTD::unitbuf(*cerr_ptr
);
66 _VSTD::unitbuf(*wcerr_ptr
);
67 #ifndef _LIBCPP_HAS_NO_STDOUT
68 cerr_ptr
->tie(cout_ptr
);
69 wcerr_ptr
->tie(wcout_ptr
);
73 ios_base::Init::~Init()
75 #ifndef _LIBCPP_HAS_NO_STDOUT
76 ostream
* cout_ptr
= reinterpret_cast<ostream
*>(cout
);
77 wostream
* wcout_ptr
= reinterpret_cast<wostream
*>(wcout
);
82 ostream
* clog_ptr
= reinterpret_cast<ostream
*>(clog
);
83 wostream
* wclog_ptr
= reinterpret_cast<wostream
*>(wclog
);
88 _LIBCPP_END_NAMESPACE_STD