brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.3 KiB · e0f14a8 Raw
42 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9#include <__config>10#if _LIBCPP_HAS_FILESYSTEM11#  include <fstream>12#endif13#include <ostream>14 15#include "std_stream.h"16 17_LIBCPP_BEGIN_NAMESPACE_STD18 19_LIBCPP_EXPORTED_FROM_ABI FILE* __get_ostream_file(ostream& __os) {20  // dynamic_cast requires RTTI, this only affects users whose vendor builds21  // the dylib with RTTI disabled. It does not affect users who build with RTTI22  // disabled but use a dylib where the RTTI is enabled.23  //24  // Returning a nullptr means the stream is not considered a terminal and the25  // special terminal handling is not done. The terminal handling is mainly of26  // importance on Windows.27#if _LIBCPP_HAS_RTTI28  auto* __rdbuf = __os.rdbuf();29#  if _LIBCPP_HAS_FILESYSTEM30  if (auto* __buffer = dynamic_cast<filebuf*>(__rdbuf))31    return __buffer->__file_;32#  endif33 34  if (auto* __buffer = dynamic_cast<__stdoutbuf<char>*>(__rdbuf))35    return __buffer->__file_;36#endif // _LIBCPP_HAS_RTTI37 38  return nullptr;39}40 41_LIBCPP_END_NAMESPACE_STD42