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