1cb14a3feSDimitry Andric //===----------------------------------------------------------------------===// 2cb14a3feSDimitry Andric // 3cb14a3feSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4cb14a3feSDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5cb14a3feSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6cb14a3feSDimitry Andric // 7cb14a3feSDimitry Andric //===----------------------------------------------------------------------===// 8cb14a3feSDimitry Andric 9cb14a3feSDimitry Andric #include <__availability> 10cb14a3feSDimitry Andric #include <__config> 11cb14a3feSDimitry Andric #ifndef _LIBCPP_HAS_NO_FILESYSTEM 12cb14a3feSDimitry Andric # include <fstream> 13cb14a3feSDimitry Andric #endif 14cb14a3feSDimitry Andric #include <ostream> 15cb14a3feSDimitry Andric 16cb14a3feSDimitry Andric #include "std_stream.h" 17cb14a3feSDimitry Andric 18cb14a3feSDimitry Andric _LIBCPP_BEGIN_NAMESPACE_STD 19cb14a3feSDimitry Andric 20*7a6dacacSDimitry Andric _LIBCPP_EXPORTED_FROM_ABI FILE* __get_ostream_file(ostream& __os) { 21cb14a3feSDimitry Andric // dynamic_cast requires RTTI, this only affects users whose vendor builds 22cb14a3feSDimitry Andric // the dylib with RTTI disabled. It does not affect users who build with RTTI 23cb14a3feSDimitry Andric // disabled but use a dylib where the RTTI is enabled. 24cb14a3feSDimitry Andric // 25cb14a3feSDimitry Andric // Returning a nullptr means the stream is not considered a terminal and the 26cb14a3feSDimitry Andric // special terminal handling is not done. The terminal handling is mainly of 27cb14a3feSDimitry Andric // importance on Windows. 28cb14a3feSDimitry Andric #ifndef _LIBCPP_HAS_NO_RTTI 29cb14a3feSDimitry Andric auto* __rdbuf = __os.rdbuf(); 30cb14a3feSDimitry Andric # ifndef _LIBCPP_HAS_NO_FILESYSTEM 31cb14a3feSDimitry Andric if (auto* __buffer = dynamic_cast<filebuf*>(__rdbuf)) 32cb14a3feSDimitry Andric return __buffer->__file_; 33cb14a3feSDimitry Andric # endif 34cb14a3feSDimitry Andric 35cb14a3feSDimitry Andric if (auto* __buffer = dynamic_cast<__stdoutbuf<char>*>(__rdbuf)) 36cb14a3feSDimitry Andric return __buffer->__file_; 37cb14a3feSDimitry Andric #endif // _LIBCPP_HAS_NO_RTTI 38cb14a3feSDimitry Andric 39cb14a3feSDimitry Andric return nullptr; 40cb14a3feSDimitry Andric } 41cb14a3feSDimitry Andric 42cb14a3feSDimitry Andric _LIBCPP_END_NAMESPACE_STD 43