def StdIOAPI : PublicAPI<"stdio.h"> {
let Macros = [
SimpleMacroDef<"stderr", "stderr">,
+ SimpleMacroDef<"stdin", "stdin">,
SimpleMacroDef<"stdout", "stdout">,
SimpleMacroDef<"_IOFBF", "0">,
SimpleMacroDef<"_IOLBF", "1">,
libc.src.stdio.putchar
libc.src.stdio.puts
libc.src.stdio.stderr
+ libc.src.stdio.stdin
libc.src.stdio.stdout
# stdlib.h entrypoints
HeaderSpec StdIO = HeaderSpec<
"stdio.h",
[
+ Macro<"stdin">,
Macro<"stderr">,
Macro<"stdout">,
Macro<"_IOFBF">,
],
[
ObjectSpec<
+ "stdin",
+ "FILE *"
+ >,
+ ObjectSpec<
"stdout",
"FILE *"
>,
// library.
File *openfile(const char *path, const char *mode);
+extern File *stdin;
extern File *stdout;
extern File *stderr;
return file;
}
+constexpr size_t STDIN_BUFFER_SIZE = 512;
+char stdin_buffer[STDIN_BUFFER_SIZE];
+static LinuxFile StdIn(0, stdin_buffer, STDIN_BUFFER_SIZE, _IOFBF, false,
+ File::ModeFlags(File::OpenMode::READ));
+File *stdin = &StdIn;
+
constexpr size_t STDOUT_BUFFER_SIZE = 1024;
char stdout_buffer[STDOUT_BUFFER_SIZE];
static LinuxFile StdOut(1, stdout_buffer, STDOUT_BUFFER_SIZE, _IOLBF, false,
)
add_entrypoint_object(
+ stdin
+ SRCS
+ stdin.cpp
+ HDRS
+ stdin.h
+ DEPENDS
+ libc.include.stdio
+ libc.src.__support.File.file
+ libc.src.__support.File.platform_file
+)
+
+add_entrypoint_object(
stdout
SRCS
stdout.cpp
--- /dev/null
+//===-- Definition of the global stdin object -----------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "src/__support/File/file.h"
+
+#include <stdio.h>
+
+extern "C" FILE *stdin = reinterpret_cast<FILE *>(__llvm_libc::stdin);
--- /dev/null
+//===------------------------------------------------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#error "Do not include this file. Instead include __support/File/file.h."