[libcxx-commits] [libcxx] [libc++] Move _LIBCPP_FOPEN_CLOEXEC_MODE to <fstream> (PR #205537)

Nikolas Klauser via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jun 24 05:04:14 PDT 2026


https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/205537

The macro is only required inside `<fstream>`, so we can move it there instead of having it as a general configuration macro.


>From a6ab4e4837a3df35156fa5c317f50c4e9f0d8355 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser <nikolasklauser at berlin.de>
Date: Wed, 24 Jun 2026 14:03:30 +0200
Subject: [PATCH] [libc++] Move _LIBCPP_FOPEN_CLOEXEC_MODE to <fstream>

---
 libcxx/include/__config | 11 -----------
 libcxx/include/fstream  | 11 +++++++++++
 2 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/libcxx/include/__config b/libcxx/include/__config
index fdd0558fbec6f..120c086ee58d0 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -400,17 +400,6 @@ typedef __char32_t char32_t;
 #    endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
 #  endif   // _LIBCPP_NO_AUTO_LINK
 
-// Configures the fopen close-on-exec mode character, if any. This string will
-// be appended to any mode string used by fstream for fopen/fdopen.
-//
-// Not all platforms support this, but it helps avoid fd-leaks on platforms that
-// do.
-#  if defined(__BIONIC__)
-#    define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
-#  else
-#    define _LIBCPP_FOPEN_CLOEXEC_MODE
-#  endif
-
 // c8rtomb() and mbrtoc8() were added in C++20 and C23. Support for these
 // functions is gradually being added to existing C libraries. The conditions
 // below check for known C library versions and conditions under which these
diff --git a/libcxx/include/fstream b/libcxx/include/fstream
index b5fb65820628a..0c34c9149de0d 100644
--- a/libcxx/include/fstream
+++ b/libcxx/include/fstream
@@ -600,6 +600,17 @@ inline bool basic_filebuf<_CharT, _Traits>::is_open() const {
   return __file_ != nullptr;
 }
 
+// Configures the fopen close-on-exec mode character, if any. This string will
+// be appended to any mode string used by fstream for fopen/fdopen.
+//
+// Not all platforms support this, but it helps avoid fd-leaks on platforms that
+// do.
+#    if defined(__BIONIC__)
+#      define _LIBCPP_FOPEN_CLOEXEC_MODE "e"
+#    else
+#      define _LIBCPP_FOPEN_CLOEXEC_MODE
+#    endif
+
 template <class _CharT, class _Traits>
 const char* basic_filebuf<_CharT, _Traits>::__make_mdstring(ios_base::openmode __mode) _NOEXCEPT {
   switch (__mode & ~ios_base::ate) {



More information about the libcxx-commits mailing list