[libc-commits] [libc] c63112a - [libc][stdio] Use proxy headers of stdio.h in src and test folders. (#110067)
via libc-commits
libc-commits at lists.llvm.org
Tue Oct 1 08:48:10 PDT 2024
Author: lntue
Date: 2024-10-01T11:48:07-04:00
New Revision: c63112a9118277a20ae440f3f69189c0937e8f4d
URL: https://github.com/llvm/llvm-project/commit/c63112a9118277a20ae440f3f69189c0937e8f4d
DIFF: https://github.com/llvm/llvm-project/commit/c63112a9118277a20ae440f3f69189c0937e8f4d.diff
LOG: [libc][stdio] Use proxy headers of stdio.h in src and test folders. (#110067)
https://github.com/llvm/llvm-project/issues/60481
Added:
libc/hdr/stdio_overlay.h
Modified:
libc/hdr/CMakeLists.txt
libc/hdr/stdio_macros.h
libc/hdr/types/CMakeLists.txt
libc/hdr/types/FILE.h
libc/hdr/types/cookie_io_functions_t.h
libc/hdr/types/off_t.h
libc/include/llvm-libc-macros/stdio-macros.h
libc/src/__support/File/linux/CMakeLists.txt
libc/src/stdio/asprintf.h
libc/src/stdio/gpu/CMakeLists.txt
libc/src/stdio/gpu/file.h
libc/src/stdio/gpu/fprintf.cpp
libc/src/stdio/gpu/getchar.cpp
libc/src/stdio/gpu/printf.cpp
libc/src/stdio/gpu/putchar.cpp
libc/src/stdio/gpu/puts.cpp
libc/src/stdio/gpu/vfprintf.cpp
libc/src/stdio/gpu/vfprintf_utils.h
libc/src/stdio/gpu/vprintf.cpp
libc/src/stdio/linux/CMakeLists.txt
libc/src/stdio/printf_core/CMakeLists.txt
libc/src/stdio/vsscanf.cpp
libc/test/src/__support/File/file_test.cpp
libc/test/src/__support/File/platform_file_test.cpp
libc/test/src/fcntl/fcntl_test.cpp
libc/test/src/math/smoke/RIntTest.h
libc/test/src/stdio/fgetc_test.cpp
libc/test/src/stdio/fgetc_unlocked_test.cpp
libc/test/src/stdio/fgets_test.cpp
libc/test/src/stdio/fileop_test.cpp
libc/test/src/stdio/fopencookie_test.cpp
libc/test/src/stdio/fprintf_test.cpp
libc/test/src/stdio/fscanf_test.cpp
libc/test/src/stdio/ftell_test.cpp
libc/test/src/stdio/putc_test.cpp
libc/test/src/stdio/setbuf_test.cpp
libc/test/src/stdio/setvbuf_test.cpp
libc/test/src/stdio/sscanf_test.cpp
libc/test/src/stdio/ungetc_test.cpp
libc/test/src/stdio/unlocked_fileop_test.cpp
libc/test/src/stdio/vfprintf_test.cpp
libc/test/src/stdio/vfscanf_test.cpp
libc/test/src/unistd/getopt_test.cpp
libc/test/src/wchar/wctob_test.cpp
Removed:
################################################################################
diff --git a/libc/hdr/CMakeLists.txt b/libc/hdr/CMakeLists.txt
index 5e3122f59de9ed..13dc892978bb87 100644
--- a/libc/hdr/CMakeLists.txt
+++ b/libc/hdr/CMakeLists.txt
@@ -78,10 +78,14 @@ add_proxy_header_library(
libc.include.signal
)
+add_header_library(stdio_overlay HDRS stdio_overlay.h)
+
add_proxy_header_library(
stdio_macros
HDRS
stdio_macros.h
+ DEPENDS
+ .stdio_overlay
FULL_BUILD_DEPENDS
libc.include.stdio
libc.include.llvm-libc-macros.stdio_macros
diff --git a/libc/hdr/stdio_macros.h b/libc/hdr/stdio_macros.h
index a212846dd8f411..a4d6a972ec9ac9 100644
--- a/libc/hdr/stdio_macros.h
+++ b/libc/hdr/stdio_macros.h
@@ -16,7 +16,7 @@
#else // Overlay mode
-#include <stdio.h>
+#include "stdio_overlay.h"
#endif // LLVM_LIBC_FULL_BUILD
diff --git a/libc/hdr/stdio_overlay.h b/libc/hdr/stdio_overlay.h
new file mode 100644
index 00000000000000..cec55abfde7bf6
--- /dev/null
+++ b/libc/hdr/stdio_overlay.h
@@ -0,0 +1,47 @@
+//===-- Including stdio.h in overlay mode ---------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_HDR_STDIO_OVERLAY_H
+#define LLVM_LIBC_HDR_STDIO_OVERLAY_H
+
+#ifdef LIBC_FULL_BUILD
+#error "This header should only be included in overlay mode"
+#endif
+
+// Overlay mode
+
+// glibc <stdio.h> header might provide extern inline definitions for few
+// functions, causing external alias errors. They are guarded by
+// `__USE_EXTERN_INLINES` macro. We temporarily disable `__USE_EXTERN_INLINES`
+// macro by defining `__NO_INLINE__` before including <stdio.h>.
+// And the same with `__USE_FORTIFY_LEVEL`, which will be temporarily disabled
+// with `_FORTIFY_SOURCE`.
+
+#ifdef _FORTIFY_SOURCE
+#define LIBC_OLD_FORTIFY_SOURCE _FORTIFY_SOURCE
+#undef _FORTIFY_SOURCE
+#endif
+
+#ifndef __NO_INLINE__
+#define __NO_INLINE__ 1
+#define LIBC_SET_NO_INLINE
+#endif
+
+#include <stdio.h>
+
+#ifdef LIBC_OLD_FORTIFY_SOURCE
+#define _FORTIFY_SOURCE LIBC_OLD_FORTIFY_SOURCE
+#undef LIBC_OLD_FORTIFY_SOURCE
+#endif
+
+#ifdef LIBC_SET_NO_INLINE
+#undef __NO_INLINE__
+#undef LIBC_SET_NO_INLINE
+#endif
+
+#endif // LLVM_LIBC_HDR_STDIO_OVERLAY_H
diff --git a/libc/hdr/types/CMakeLists.txt b/libc/hdr/types/CMakeLists.txt
index b4de39621416f7..fab5245816bbe1 100644
--- a/libc/hdr/types/CMakeLists.txt
+++ b/libc/hdr/types/CMakeLists.txt
@@ -140,6 +140,8 @@ add_proxy_header_library(
FILE
HDRS
FILE.h
+ DEPENDS
+ libc.hdr.stdio_overlay
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.FILE
libc.include.stdio
@@ -149,6 +151,8 @@ add_proxy_header_library(
off_t
HDRS
off_t.h
+ DEPENDS
+ libc.hdr.stdio_overlay
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.off_t
libc.include.stdio
@@ -158,6 +162,8 @@ add_proxy_header_library(
cookie_io_functions_t
HDRS
cookie_io_functions_t.h
+ DEPENDS
+ libc.hdr.stdio_overlay
FULL_BUILD_DEPENDS
libc.include.llvm-libc-types.cookie_io_functions_t
libc.include.stdio
diff --git a/libc/hdr/types/FILE.h b/libc/hdr/types/FILE.h
index 60e95f07e37f91..ecb52b7102cb0e 100644
--- a/libc/hdr/types/FILE.h
+++ b/libc/hdr/types/FILE.h
@@ -15,7 +15,7 @@
#else // Overlay mode
-#include <stdio.h>
+#include "hdr/stdio_overlay.h"
#endif // LLVM_LIBC_FULL_BUILD
diff --git a/libc/hdr/types/cookie_io_functions_t.h b/libc/hdr/types/cookie_io_functions_t.h
index d8fe7731a84bda..7323a05001c407 100644
--- a/libc/hdr/types/cookie_io_functions_t.h
+++ b/libc/hdr/types/cookie_io_functions_t.h
@@ -15,7 +15,7 @@
#else // Overlay mode
-#include <stdio.h>
+#include "hdr/stdio_overlay.h"
#endif // LLVM_LIBC_FULL_BUILD
diff --git a/libc/hdr/types/off_t.h b/libc/hdr/types/off_t.h
index abc3aa659365f7..52337e5b63e2dc 100644
--- a/libc/hdr/types/off_t.h
+++ b/libc/hdr/types/off_t.h
@@ -15,7 +15,7 @@
#else // Overlay mode
-#include <stdio.h>
+#include "hdr/stdio_overlay.h"
#endif // LLVM_LIBC_FULL_BUILD
diff --git a/libc/include/llvm-libc-macros/stdio-macros.h b/libc/include/llvm-libc-macros/stdio-macros.h
index 69fb71ad3f6515..96f0e6933ade68 100644
--- a/libc/include/llvm-libc-macros/stdio-macros.h
+++ b/libc/include/llvm-libc-macros/stdio-macros.h
@@ -9,6 +9,30 @@
#ifndef LLVM_LIBC_MACROS_STDIO_MACROS_H
#define LLVM_LIBC_MACROS_STDIO_MACROS_H
+#include "../llvm-libc-types/FILE.h"
+
+#ifdef __cplusplus
+extern "C" FILE *stdin;
+extern "C" FILE *stdout;
+extern "C" FILE *stderr;
+#else
+extern FILE *stdin;
+extern FILE *stdout;
+extern FILE *stderr;
+#endif
+
+#ifndef stdin
+#define stdin stdin
+#endif
+
+#ifndef stdout
+#define stdout stdout
+#endif
+
+#ifndef stderr
+#define stderr stderr
+#endif
+
#ifndef EOF
#define EOF (-1)
#endif
@@ -19,4 +43,16 @@
#define _IOLBF 1
#define _IOFBF 0
+#ifndef SEEK_SET
+#define SEEK_SET 0
+#endif
+
+#ifndef SEEK_CUR
+#define SEEK_CUR 1
+#endif
+
+#ifndef SEEK_END
+#define SEEK_END 2
+#endif
+
#endif // LLVM_LIBC_MACROS_STDIO_MACROS_H
diff --git a/libc/src/__support/File/linux/CMakeLists.txt b/libc/src/__support/File/linux/CMakeLists.txt
index 5556b812596f83..5abbf11b3671cd 100644
--- a/libc/src/__support/File/linux/CMakeLists.txt
+++ b/libc/src/__support/File/linux/CMakeLists.txt
@@ -8,7 +8,6 @@ add_object_library(
lseekImpl.h
DEPENDS
libc.include.fcntl
- libc.include.stdio
libc.include.sys_syscall
libc.include.sys_stat
libc.src.__support.CPP.new
diff --git a/libc/src/stdio/asprintf.h b/libc/src/stdio/asprintf.h
index fd2b908db171df..0c0d5a350829e7 100644
--- a/libc/src/stdio/asprintf.h
+++ b/libc/src/stdio/asprintf.h
@@ -10,8 +10,6 @@
#define LLVM_LIBC_SRC_STDIO_ASPRINTF_H
#include "src/__support/macros/config.h"
-#include <stdarg.h>
-#include <stdio.h>
namespace LIBC_NAMESPACE {
diff --git a/libc/src/stdio/gpu/CMakeLists.txt b/libc/src/stdio/gpu/CMakeLists.txt
index 9cac42ed71fb76..c4ad333e251639 100644
--- a/libc/src/stdio/gpu/CMakeLists.txt
+++ b/libc/src/stdio/gpu/CMakeLists.txt
@@ -1,9 +1,40 @@
+add_entrypoint_object(
+ stdin
+ SRCS
+ stdin.cpp
+ HDRS
+ ../stdin.h
+ DEPENDS
+ libc.hdr.types.FILE
+)
+
+add_entrypoint_object(
+ stdout
+ SRCS
+ stdout.cpp
+ HDRS
+ ../stdout.h
+ DEPENDS
+ libc.hdr.types.FILE
+)
+
+add_entrypoint_object(
+ stderr
+ SRCS
+ stderr.cpp
+ HDRS
+ ../stderr.h
+ DEPENDS
+ libc.hdr.types.FILE
+)
+
add_header_library(
gpu_file
HDRS
file.h
DEPENDS
libc.hdr.types.FILE
+ libc.hdr.stdio_macros
libc.src.__support.RPC.rpc_client
libc.src.__support.common
.stdin
@@ -123,7 +154,6 @@ add_entrypoint_object(
../puts.h
DEPENDS
libc.hdr.types.FILE
- libc.include.stdio # needed for stdin
.gpu_file
)
@@ -168,7 +198,6 @@ add_entrypoint_object(
../putc.h
DEPENDS
libc.hdr.types.FILE
- libc.include.stdio # needed for stdin
.gpu_file
)
@@ -180,7 +209,6 @@ add_entrypoint_object(
../putchar.h
DEPENDS
libc.hdr.types.FILE
- libc.include.stdio # needed for stdin
.gpu_file
)
@@ -203,7 +231,6 @@ add_entrypoint_object(
../getc.h
DEPENDS
libc.hdr.types.FILE
- libc.include.stdio # needed for stdin
.gpu_file
)
@@ -215,7 +242,6 @@ add_entrypoint_object(
../getchar.h
DEPENDS
libc.hdr.types.FILE
- libc.include.stdio # needed for stdin
.gpu_file
)
@@ -304,33 +330,3 @@ add_entrypoint_object(
libc.hdr.types.FILE
.gpu_file
)
-
-add_entrypoint_object(
- stdin
- SRCS
- stdin.cpp
- HDRS
- ../stdin.h
- DEPENDS
- libc.hdr.types.FILE
-)
-
-add_entrypoint_object(
- stdout
- SRCS
- stdout.cpp
- HDRS
- ../stdout.h
- DEPENDS
- libc.hdr.types.FILE
-)
-
-add_entrypoint_object(
- stderr
- SRCS
- stderr.cpp
- HDRS
- ../stderr.h
- DEPENDS
- libc.hdr.types.FILE
-)
diff --git a/libc/src/stdio/gpu/file.h b/libc/src/stdio/gpu/file.h
index 5de76842d7beab..0856a3430803ae 100644
--- a/libc/src/stdio/gpu/file.h
+++ b/libc/src/stdio/gpu/file.h
@@ -10,10 +10,9 @@
#include "src/__support/macros/config.h"
#include "src/string/string_utils.h"
+#include "hdr/stdio_macros.h" // For stdin/out/err
#include "hdr/types/FILE.h"
-#include <stdio.h> //needed for stdin/out/err
-
namespace LIBC_NAMESPACE_DECL {
namespace file {
diff --git a/libc/src/stdio/gpu/fprintf.cpp b/libc/src/stdio/gpu/fprintf.cpp
index 42d6ad00877734..6222589cc4bab9 100644
--- a/libc/src/stdio/gpu/fprintf.cpp
+++ b/libc/src/stdio/gpu/fprintf.cpp
@@ -8,12 +8,13 @@
#include "src/stdio/fprintf.h"
+#include "hdr/types/FILE.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/arg_list.h"
#include "src/errno/libc_errno.h"
#include "src/stdio/gpu/vfprintf_utils.h"
-#include <stdio.h>
+#include <stdarg.h>
namespace LIBC_NAMESPACE {
diff --git a/libc/src/stdio/gpu/getchar.cpp b/libc/src/stdio/gpu/getchar.cpp
index 048cf23b0d64a5..d99b97b5c5a008 100644
--- a/libc/src/stdio/gpu/getchar.cpp
+++ b/libc/src/stdio/gpu/getchar.cpp
@@ -10,10 +10,7 @@
#include "file.h"
#include "src/__support/macros/config.h"
-#include "hdr/stdio_macros.h" // for EOF.
-#include "hdr/types/FILE.h"
-
-#include <stdio.h> //needed for stdin
+#include "hdr/stdio_macros.h" // for EOF and stdin.
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/stdio/gpu/printf.cpp b/libc/src/stdio/gpu/printf.cpp
index 63af6fffeea73c..d9903193ef1658 100644
--- a/libc/src/stdio/gpu/printf.cpp
+++ b/libc/src/stdio/gpu/printf.cpp
@@ -13,7 +13,7 @@
#include "src/errno/libc_errno.h"
#include "src/stdio/gpu/vfprintf_utils.h"
-#include <stdio.h>
+#include <stdarg.h>
namespace LIBC_NAMESPACE {
diff --git a/libc/src/stdio/gpu/putchar.cpp b/libc/src/stdio/gpu/putchar.cpp
index d03a3fe68daf7a..c49b02e2f1f10f 100644
--- a/libc/src/stdio/gpu/putchar.cpp
+++ b/libc/src/stdio/gpu/putchar.cpp
@@ -10,10 +10,7 @@
#include "file.h"
#include "src/__support/macros/config.h"
-#include "hdr/stdio_macros.h" // for EOF.
-#include "hdr/types/FILE.h"
-
-#include <stdio.h> //needed for stdout
+#include "hdr/stdio_macros.h" // for EOF and stdout.
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/stdio/gpu/puts.cpp b/libc/src/stdio/gpu/puts.cpp
index af84432d1ef8c7..20f7a889a378a1 100644
--- a/libc/src/stdio/gpu/puts.cpp
+++ b/libc/src/stdio/gpu/puts.cpp
@@ -12,10 +12,7 @@
#include "src/errno/libc_errno.h"
#include "src/stdio/gpu/file.h"
-#include "hdr/stdio_macros.h" // for EOF.
-#include "hdr/types/FILE.h"
-
-#include <stdio.h> //needed for stdout
+#include "hdr/stdio_macros.h" // for EOF and stdout.
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/src/stdio/gpu/vfprintf.cpp b/libc/src/stdio/gpu/vfprintf.cpp
index f314f6872ad0e4..961cfa48579e0a 100644
--- a/libc/src/stdio/gpu/vfprintf.cpp
+++ b/libc/src/stdio/gpu/vfprintf.cpp
@@ -8,13 +8,12 @@
#include "src/stdio/vfprintf.h"
+#include "hdr/types/FILE.h"
#include "src/__support/CPP/string_view.h"
#include "src/__support/arg_list.h"
#include "src/errno/libc_errno.h"
#include "src/stdio/gpu/vfprintf_utils.h"
-#include <stdio.h>
-
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(int, vfprintf,
diff --git a/libc/src/stdio/gpu/vfprintf_utils.h b/libc/src/stdio/gpu/vfprintf_utils.h
index f364646fcea58f..7c012d139ba5dc 100644
--- a/libc/src/stdio/gpu/vfprintf_utils.h
+++ b/libc/src/stdio/gpu/vfprintf_utils.h
@@ -6,13 +6,12 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/types/FILE.h"
#include "src/__support/RPC/rpc_client.h"
#include "src/__support/arg_list.h"
#include "src/stdio/gpu/file.h"
#include "src/string/string_utils.h"
-#include <stdio.h>
-
namespace LIBC_NAMESPACE {
template <uint16_t opcode>
diff --git a/libc/src/stdio/gpu/vprintf.cpp b/libc/src/stdio/gpu/vprintf.cpp
index 1356aceeb51c52..2bb74d7f017b59 100644
--- a/libc/src/stdio/gpu/vprintf.cpp
+++ b/libc/src/stdio/gpu/vprintf.cpp
@@ -13,8 +13,6 @@
#include "src/errno/libc_errno.h"
#include "src/stdio/gpu/vfprintf_utils.h"
-#include <stdio.h>
-
namespace LIBC_NAMESPACE {
LLVM_LIBC_FUNCTION(int, vprintf,
diff --git a/libc/src/stdio/linux/CMakeLists.txt b/libc/src/stdio/linux/CMakeLists.txt
index fa36732a159be1..d6241e1ca0439d 100644
--- a/libc/src/stdio/linux/CMakeLists.txt
+++ b/libc/src/stdio/linux/CMakeLists.txt
@@ -6,7 +6,6 @@ add_entrypoint_object(
../remove.h
DEPENDS
libc.include.fcntl
- libc.include.stdio
libc.include.unistd
libc.include.sys_syscall
libc.src.__support.OSUtil.osutil
@@ -32,7 +31,6 @@ add_entrypoint_object(
HDRS
../fdopen.h
DEPENDS
- libc.include.stdio
libc.src.__support.File.file
libc.src.__support.File.platform_file
)
diff --git a/libc/src/stdio/printf_core/CMakeLists.txt b/libc/src/stdio/printf_core/CMakeLists.txt
index 1095f01d71f24e..542327ad5a49a9 100644
--- a/libc/src/stdio/printf_core/CMakeLists.txt
+++ b/libc/src/stdio/printf_core/CMakeLists.txt
@@ -141,7 +141,6 @@ add_header_library(
HDRS
vfprintf_internal.h
DEPENDS
- libc.include.stdio
libc.src.__support.File.file
libc.src.__support.arg_list
libc.src.stdio.printf_core.printf_main
diff --git a/libc/src/stdio/vsscanf.cpp b/libc/src/stdio/vsscanf.cpp
index fcf0b88885f17b..f3f56bce64292b 100644
--- a/libc/src/stdio/vsscanf.cpp
+++ b/libc/src/stdio/vsscanf.cpp
@@ -8,13 +8,13 @@
#include "src/stdio/vsscanf.h"
+#include "hdr/stdio_macros.h"
#include "src/__support/CPP/limits.h"
#include "src/__support/arg_list.h"
#include "src/stdio/scanf_core/reader.h"
#include "src/stdio/scanf_core/scanf_main.h"
#include <stdarg.h>
-#include <stdio.h>
namespace LIBC_NAMESPACE_DECL {
diff --git a/libc/test/src/__support/File/file_test.cpp b/libc/test/src/__support/File/file_test.cpp
index 2f68c3faa0ad08..5977ea7c8e0b57 100644
--- a/libc/test/src/__support/File/file_test.cpp
+++ b/libc/test/src/__support/File/file_test.cpp
@@ -12,7 +12,6 @@
#include "test/UnitTest/MemoryMatcher.h"
#include "test/UnitTest/Test.h"
-#include <stdio.h>
#include <stdlib.h>
using ModeFlags = LIBC_NAMESPACE::File::ModeFlags;
diff --git a/libc/test/src/__support/File/platform_file_test.cpp b/libc/test/src/__support/File/platform_file_test.cpp
index 8aa07219a6527b..6b2be2a1493299 100644
--- a/libc/test/src/__support/File/platform_file_test.cpp
+++ b/libc/test/src/__support/File/platform_file_test.cpp
@@ -9,7 +9,7 @@
#include "src/__support/File/file.h"
#include "test/UnitTest/Test.h"
-#include <stdio.h> // For SEEK_* macros
+#include "hdr/stdio_macros.h" // For SEEK_* macros
using File = LIBC_NAMESPACE::File;
constexpr char TEXT[] = "Hello, File";
diff --git a/libc/test/src/fcntl/fcntl_test.cpp b/libc/test/src/fcntl/fcntl_test.cpp
index ffbb3ec337ed4d..1a21afe51085b1 100644
--- a/libc/test/src/fcntl/fcntl_test.cpp
+++ b/libc/test/src/fcntl/fcntl_test.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "hdr/fcntl_macros.h"
+#include "hdr/stdio_macros.h"
#include "hdr/types/struct_flock.h"
#include "src/errno/libc_errno.h"
#include "src/fcntl/fcntl.h"
@@ -16,7 +17,6 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
-#include <stdio.h>
#include <sys/stat.h> // For S_IRWXU
TEST(LlvmLibcFcntlTest, FcntlDupfd) {
diff --git a/libc/test/src/math/smoke/RIntTest.h b/libc/test/src/math/smoke/RIntTest.h
index 1412c3f27a2d5f..fb2c89c4980b48 100644
--- a/libc/test/src/math/smoke/RIntTest.h
+++ b/libc/test/src/math/smoke/RIntTest.h
@@ -17,7 +17,6 @@
#include "hdr/fenv_macros.h"
#include "hdr/math_macros.h"
-#include <stdio.h>
static constexpr int ROUNDING_MODES[4] = {FE_UPWARD, FE_DOWNWARD, FE_TOWARDZERO,
FE_TONEAREST};
diff --git a/libc/test/src/stdio/fgetc_test.cpp b/libc/test/src/stdio/fgetc_test.cpp
index 989bb312afadf4..2cc8436bd66f28 100644
--- a/libc/test/src/stdio/fgetc_test.cpp
+++ b/libc/test/src/stdio/fgetc_test.cpp
@@ -16,8 +16,8 @@
#include "src/stdio/getc.h"
#include "test/UnitTest/Test.h"
+#include "hdr/stdio_macros.h"
#include "src/errno/libc_errno.h"
-#include <stdio.h>
class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::Test {
public:
diff --git a/libc/test/src/stdio/fgetc_unlocked_test.cpp b/libc/test/src/stdio/fgetc_unlocked_test.cpp
index 48d7a043cad7c3..46cf12c2c253be 100644
--- a/libc/test/src/stdio/fgetc_unlocked_test.cpp
+++ b/libc/test/src/stdio/fgetc_unlocked_test.cpp
@@ -19,8 +19,8 @@
#include "src/stdio/getc_unlocked.h"
#include "test/UnitTest/Test.h"
+#include "hdr/stdio_macros.h"
#include "src/errno/libc_errno.h"
-#include <stdio.h>
class LlvmLibcGetcTest : public LIBC_NAMESPACE::testing::Test {
public:
diff --git a/libc/test/src/stdio/fgets_test.cpp b/libc/test/src/stdio/fgets_test.cpp
index 39337262f1e008..a8a2c62f07b5ea 100644
--- a/libc/test/src/stdio/fgets_test.cpp
+++ b/libc/test/src/stdio/fgets_test.cpp
@@ -15,7 +15,6 @@
#include "test/UnitTest/Test.h"
#include "src/errno/libc_errno.h"
-#include <stdio.h>
TEST(LlvmLibcFgetsTest, WriteAndReadCharacters) {
constexpr char FILENAME[] = "testdata/fgets.test";
diff --git a/libc/test/src/stdio/fileop_test.cpp b/libc/test/src/stdio/fileop_test.cpp
index 0fbe19cf08d837..98ead6edd38b47 100644
--- a/libc/test/src/stdio/fileop_test.cpp
+++ b/libc/test/src/stdio/fileop_test.cpp
@@ -20,8 +20,8 @@
#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
+#include "hdr/stdio_macros.h"
#include "src/errno/libc_errno.h"
-#include <stdio.h>
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::EQ;
using LIBC_NAMESPACE::testing::ErrnoSetterMatcher::NE;
diff --git a/libc/test/src/stdio/fopencookie_test.cpp b/libc/test/src/stdio/fopencookie_test.cpp
index 6c86b8759801e1..016722aa11ab82 100644
--- a/libc/test/src/stdio/fopencookie_test.cpp
+++ b/libc/test/src/stdio/fopencookie_test.cpp
@@ -18,8 +18,8 @@
#include "test/UnitTest/MemoryMatcher.h"
#include "test/UnitTest/Test.h"
+#include "hdr/stdio_macros.h"
#include "src/errno/libc_errno.h"
-#include <stdio.h>
#include <stdlib.h>
using MemoryView = LIBC_NAMESPACE::testing::MemoryView;
diff --git a/libc/test/src/stdio/fprintf_test.cpp b/libc/test/src/stdio/fprintf_test.cpp
index 08b31795b435b2..82a3e039d9baad 100644
--- a/libc/test/src/stdio/fprintf_test.cpp
+++ b/libc/test/src/stdio/fprintf_test.cpp
@@ -17,8 +17,6 @@
#include "test/UnitTest/Test.h"
-#include <stdio.h>
-
namespace printf_test {
#ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE
using LIBC_NAMESPACE::fclose;
diff --git a/libc/test/src/stdio/fscanf_test.cpp b/libc/test/src/stdio/fscanf_test.cpp
index 701090788ca10c..e5b8c4f422bacd 100644
--- a/libc/test/src/stdio/fscanf_test.cpp
+++ b/libc/test/src/stdio/fscanf_test.cpp
@@ -19,8 +19,6 @@
#include "test/UnitTest/Test.h"
-#include <stdio.h>
-
namespace scanf_test {
#ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE
using LIBC_NAMESPACE::fclose;
diff --git a/libc/test/src/stdio/ftell_test.cpp b/libc/test/src/stdio/ftell_test.cpp
index 62745e2194be6d..01ff071f2ee78c 100644
--- a/libc/test/src/stdio/ftell_test.cpp
+++ b/libc/test/src/stdio/ftell_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/stdio_macros.h"
#include "src/stdio/fclose.h"
#include "src/stdio/fopen.h"
#include "src/stdio/fread.h"
@@ -17,8 +18,6 @@
#include "src/stdio/setvbuf.h"
#include "test/UnitTest/Test.h"
-#include <stdio.h>
-
class LlvmLibcFTellTest : public LIBC_NAMESPACE::testing::Test {
protected:
void test_with_bufmode(int bufmode) {
diff --git a/libc/test/src/stdio/putc_test.cpp b/libc/test/src/stdio/putc_test.cpp
index 7349a97d80e19d..e881a0e2d0108b 100644
--- a/libc/test/src/stdio/putc_test.cpp
+++ b/libc/test/src/stdio/putc_test.cpp
@@ -15,8 +15,6 @@
#include "test/UnitTest/Test.h"
-#include <stdio.h>
-
TEST(LlvmLibcPutcTest, WriteToFile) {
constexpr char FILENAME[] = "testdata/putc_output.test";
::FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w");
diff --git a/libc/test/src/stdio/setbuf_test.cpp b/libc/test/src/stdio/setbuf_test.cpp
index b0abca4acf731b..25fea59076626f 100644
--- a/libc/test/src/stdio/setbuf_test.cpp
+++ b/libc/test/src/stdio/setbuf_test.cpp
@@ -6,6 +6,7 @@
//
//===----------------------------------------------------------------------===//
+#include "hdr/stdio_macros.h"
#include "src/stdio/fclose.h"
#include "src/stdio/fopen.h"
#include "src/stdio/fread.h"
@@ -14,8 +15,6 @@
#include "src/stdio/ungetc.h"
#include "test/UnitTest/Test.h"
-#include <stdio.h>
-
TEST(LlvmLibcSetbufTest, DefaultBufsize) {
// The idea in this test is to change the buffer after opening a file and
// ensure that read and write work as expected.
diff --git a/libc/test/src/stdio/setvbuf_test.cpp b/libc/test/src/stdio/setvbuf_test.cpp
index d42ebac12ead28..a1e1fee25db31d 100644
--- a/libc/test/src/stdio/setvbuf_test.cpp
+++ b/libc/test/src/stdio/setvbuf_test.cpp
@@ -13,8 +13,8 @@
#include "src/stdio/setvbuf.h"
#include "test/UnitTest/Test.h"
+#include "hdr/stdio_macros.h"
#include "src/errno/libc_errno.h"
-#include <stdio.h>
TEST(LlvmLibcSetvbufTest, SetNBFBuffer) {
// The idea in this test is that we open a file for writing and reading, and
diff --git a/libc/test/src/stdio/sscanf_test.cpp b/libc/test/src/stdio/sscanf_test.cpp
index 59be4e6de6ed65..33bb0acba3e662 100644
--- a/libc/test/src/stdio/sscanf_test.cpp
+++ b/libc/test/src/stdio/sscanf_test.cpp
@@ -6,13 +6,11 @@
//
//===----------------------------------------------------------------------===//
-#include "src/__support/CPP/limits.h"
-#include "src/__support/FPUtil/FPBits.h"
-
#include "src/stdio/sscanf.h"
-#include <stdio.h> // For EOF
-
+#include "hdr/stdio_macros.h" // For EOF
+#include "src/__support/CPP/limits.h"
+#include "src/__support/FPUtil/FPBits.h"
#include "test/UnitTest/FPMatcher.h"
#include "test/UnitTest/Test.h"
diff --git a/libc/test/src/stdio/ungetc_test.cpp b/libc/test/src/stdio/ungetc_test.cpp
index c98995ff0811bb..b9d7530fc71771 100644
--- a/libc/test/src/stdio/ungetc_test.cpp
+++ b/libc/test/src/stdio/ungetc_test.cpp
@@ -6,16 +6,16 @@
//
//===----------------------------------------------------------------------===//
+#include "src/stdio/ungetc.h"
+
+#include "hdr/stdio_macros.h"
#include "src/stdio/fclose.h"
#include "src/stdio/fopen.h"
#include "src/stdio/fread.h"
#include "src/stdio/fseek.h"
#include "src/stdio/fwrite.h"
-#include "src/stdio/ungetc.h"
#include "test/UnitTest/Test.h"
-#include <stdio.h>
-
TEST(LlvmLibcUngetcTest, UngetAndReadBack) {
constexpr char FILENAME[] = "testdata/ungetc_test.test";
::FILE *file = LIBC_NAMESPACE::fopen(FILENAME, "w");
diff --git a/libc/test/src/stdio/unlocked_fileop_test.cpp b/libc/test/src/stdio/unlocked_fileop_test.cpp
index 09697a6452f486..67f1b0ff513bc5 100644
--- a/libc/test/src/stdio/unlocked_fileop_test.cpp
+++ b/libc/test/src/stdio/unlocked_fileop_test.cpp
@@ -18,7 +18,6 @@
#include "test/UnitTest/Test.h"
#include "src/errno/libc_errno.h"
-#include <stdio.h>
TEST(LlvmLibcFILETest, UnlockedReadAndWrite) {
constexpr char fNAME[] = "testdata/unlocked_read_and_write.test";
diff --git a/libc/test/src/stdio/vfprintf_test.cpp b/libc/test/src/stdio/vfprintf_test.cpp
index 9bad2c831e5c42..80d484500d5f23 100644
--- a/libc/test/src/stdio/vfprintf_test.cpp
+++ b/libc/test/src/stdio/vfprintf_test.cpp
@@ -21,8 +21,6 @@
#include "test/UnitTest/Test.h"
-#include <stdio.h>
-
namespace printf_test {
#ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE
using LIBC_NAMESPACE::fclose;
diff --git a/libc/test/src/stdio/vfscanf_test.cpp b/libc/test/src/stdio/vfscanf_test.cpp
index fa4e27582375f8..b66538671f6206 100644
--- a/libc/test/src/stdio/vfscanf_test.cpp
+++ b/libc/test/src/stdio/vfscanf_test.cpp
@@ -19,8 +19,6 @@
#include "test/UnitTest/Test.h"
-#include <stdio.h>
-
namespace scanf_test {
#ifndef LIBC_COPT_STDIO_USE_SYSTEM_FILE
using LIBC_NAMESPACE::fclose;
diff --git a/libc/test/src/unistd/getopt_test.cpp b/libc/test/src/unistd/getopt_test.cpp
index 1ca7c99e1ce373..e6e87720cde48d 100644
--- a/libc/test/src/unistd/getopt_test.cpp
+++ b/libc/test/src/unistd/getopt_test.cpp
@@ -13,8 +13,6 @@
#include "src/stdio/fflush.h"
#include "src/stdio/fopencookie.h"
-#include <stdio.h>
-
using LIBC_NAMESPACE::cpp::array;
namespace test_globals {
diff --git a/libc/test/src/wchar/wctob_test.cpp b/libc/test/src/wchar/wctob_test.cpp
index 3f911884a7c12c..977224bf77abe0 100644
--- a/libc/test/src/wchar/wctob_test.cpp
+++ b/libc/test/src/wchar/wctob_test.cpp
@@ -6,10 +6,8 @@
//
//===----------------------------------------------------------------------===//
-#include <stdio.h> //for EOF
-
+#include "hdr/stdio_macros.h" //for EOF
#include "src/wchar/wctob.h"
-
#include "test/UnitTest/Test.h"
TEST(LlvmLibcWctob, DefaultLocale) {
More information about the libc-commits
mailing list