1cfa2d7dfSPetr Hosek //===-- Baremetal implementation of getchar -------------------------------===// 2cfa2d7dfSPetr Hosek // 3cfa2d7dfSPetr Hosek // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4cfa2d7dfSPetr Hosek // See https://llvm.org/LICENSE.txt for license information. 5cfa2d7dfSPetr Hosek // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6cfa2d7dfSPetr Hosek // 7cfa2d7dfSPetr Hosek //===----------------------------------------------------------------------===// 8cfa2d7dfSPetr Hosek 9cfa2d7dfSPetr Hosek #include "src/stdio/getchar.h" 10cfa2d7dfSPetr Hosek #include "src/__support/OSUtil/io.h" 11*5ff3ff33SPetr Hosek #include "src/__support/macros/config.h" 12cfa2d7dfSPetr Hosek 13b187ecb6SMichael Jones #include "hdr/stdio_macros.h" // for EOF. 1450a19f94SPetr Hosek 15*5ff3ff33SPetr Hosek namespace LIBC_NAMESPACE_DECL { 16cfa2d7dfSPetr Hosek 17cfa2d7dfSPetr Hosek LLVM_LIBC_FUNCTION(int, getchar, ()) { 18cfa2d7dfSPetr Hosek char buf[1]; 19cfa2d7dfSPetr Hosek auto result = read_from_stdin(buf, sizeof(buf)); 20cfa2d7dfSPetr Hosek if (result < 0) 21cfa2d7dfSPetr Hosek return EOF; 22cfa2d7dfSPetr Hosek return buf[0]; 23cfa2d7dfSPetr Hosek } 24cfa2d7dfSPetr Hosek 25*5ff3ff33SPetr Hosek } // namespace LIBC_NAMESPACE_DECL 26