• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===------------- Fuchsia implementation of IO utils -----------*- C++ -*-===//
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 //===----------------------------------------------------------------------===//
8 
9 #ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_FUCHSIA_IO_H
10 #define LLVM_LIBC_SRC___SUPPORT_OSUTIL_FUCHSIA_IO_H
11 
12 #include "src/__support/CPP/string_view.h"
13 
14 #include <iostream>
15 #include <zircon/sanitizer.h>
16 
17 namespace LIBC_NAMESPACE {
18 
write_to_stderr(cpp::string_view msg)19 LIBC_INLINE void write_to_stderr(cpp::string_view msg) {
20 #if defined(LIBC_COPT_TEST_USE_ZXTEST)
21   // This is used in standalone context where there is nothing like POSIX I/O.
22   __sanitizer_log_write(msg.data(), msg.size());
23 #elif defined(LIBC_COPT_TEST_USE_GTEST)
24   // The gtest framework already relies on full standard C++ I/O via fdio.
25   std::cerr << std::string_view{msg.data(), msg.size()};
26 #else
27 #error this file should only be used by tests
28 #endif
29 }
30 
31 } // namespace LIBC_NAMESPACE
32 
33 #endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FUCHSIA_IO_H
34