iostream.cpp 3.4 KB

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