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 #include "src/__support/macros/config.h" 14 15 #include <iostream> 16 #include <zircon/sanitizer.h> 17 18 namespace LIBC_NAMESPACE_DECL { 19 write_to_stderr(cpp::string_view msg)20LIBC_INLINE void write_to_stderr(cpp::string_view msg) { 21 #if defined(LIBC_COPT_TEST_USE_ZXTEST) 22 // This is used in standalone context where there is nothing like POSIX I/O. 23 __sanitizer_log_write(msg.data(), msg.size()); 24 #elif defined(LIBC_COPT_TEST_USE_GTEST) 25 // The gtest framework already relies on full standard C++ I/O via fdio. 26 std::cerr << std::string_view{msg.data(), msg.size()}; 27 #else 28 #error this file should only be used by tests 29 #endif 30 } 31 32 } // namespace LIBC_NAMESPACE_DECL 33 34 #endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_FUCHSIA_IO_H 35