[libc++] Avoid including <ostream> in <fstream> and <strstream> (#116014)

This reduces the include time of `<fstream>` from ~800ms to ~500ms.

GitOrigin-RevId: 1636580b0a9afb2272d94b125313e4b35e9af2a9
diff --git a/include/fstream b/include/fstream
index e3b9abb..e188bfc 100644
--- a/include/fstream
+++ b/include/fstream
@@ -193,6 +193,8 @@
 #include <__fwd/fstream.h>
 #include <__locale>
 #include <__memory/addressof.h>
+#include <__memory/unique_ptr.h>
+#include <__ostream/basic_ostream.h>
 #include <__type_traits/enable_if.h>
 #include <__type_traits/is_same.h>
 #include <__utility/move.h>
@@ -200,7 +202,7 @@
 #include <__utility/unreachable.h>
 #include <cstdio>
 #include <istream>
-#include <ostream>
+#include <streambuf>
 #include <typeinfo>
 #include <version>
 
diff --git a/include/strstream b/include/strstream
index 9ff4024..b263fe1 100644
--- a/include/strstream
+++ b/include/strstream
@@ -130,8 +130,9 @@
 */
 
 #include <__config>
+#include <__ostream/basic_ostream.h>
 #include <istream>
-#include <ostream>
+#include <streambuf>
 #include <version>
 
 #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
diff --git a/test/libcxx/transitive_includes/cxx23.csv b/test/libcxx/transitive_includes/cxx23.csv
index 854ad1b..c0cabf4 100644
--- a/test/libcxx/transitive_includes/cxx23.csv
+++ b/test/libcxx/transitive_includes/cxx23.csv
@@ -410,13 +410,11 @@
 forward_list new
 forward_list tuple
 forward_list version
-fstream array
 fstream bitset
 fstream cctype
 fstream cerrno
 fstream climits
 fstream clocale
-fstream cmath
 fstream compare
 fstream cstddef
 fstream cstdint
@@ -427,7 +425,6 @@
 fstream cwchar
 fstream cwctype
 fstream filesystem
-fstream format
 fstream initializer_list
 fstream iomanip
 fstream ios
@@ -436,9 +433,6 @@
 fstream limits
 fstream locale
 fstream new
-fstream optional
-fstream ostream
-fstream print
 fstream ratio
 fstream stdexcept
 fstream streambuf
@@ -1081,13 +1075,11 @@
 string_view new
 string_view stdexcept
 string_view version
-strstream array
 strstream bitset
 strstream cctype
 strstream cerrno
 strstream climits
 strstream clocale
-strstream cmath
 strstream compare
 strstream cstddef
 strstream cstdint
@@ -1097,7 +1089,6 @@
 strstream ctime
 strstream cwchar
 strstream cwctype
-strstream format
 strstream initializer_list
 strstream ios
 strstream iosfwd
@@ -1105,9 +1096,6 @@
 strstream limits
 strstream locale
 strstream new
-strstream optional
-strstream ostream
-strstream print
 strstream ratio
 strstream stdexcept
 strstream streambuf
diff --git a/test/libcxx/transitive_includes/cxx26.csv b/test/libcxx/transitive_includes/cxx26.csv
index ba2faae..5bbf5b4 100644
--- a/test/libcxx/transitive_includes/cxx26.csv
+++ b/test/libcxx/transitive_includes/cxx26.csv
@@ -410,13 +410,11 @@
 forward_list new
 forward_list tuple
 forward_list version
-fstream array
 fstream bitset
 fstream cctype
 fstream cerrno
 fstream climits
 fstream clocale
-fstream cmath
 fstream compare
 fstream cstddef
 fstream cstdint
@@ -426,7 +424,6 @@
 fstream ctime
 fstream cwchar
 fstream cwctype
-fstream format
 fstream initializer_list
 fstream iomanip
 fstream ios
@@ -435,9 +432,6 @@
 fstream limits
 fstream locale
 fstream new
-fstream optional
-fstream ostream
-fstream print
 fstream ratio
 fstream stdexcept
 fstream streambuf
@@ -1080,13 +1074,11 @@
 string_view new
 string_view stdexcept
 string_view version
-strstream array
 strstream bitset
 strstream cctype
 strstream cerrno
 strstream climits
 strstream clocale
-strstream cmath
 strstream compare
 strstream cstddef
 strstream cstdint
@@ -1096,7 +1088,6 @@
 strstream ctime
 strstream cwchar
 strstream cwctype
-strstream format
 strstream initializer_list
 strstream ios
 strstream iosfwd
@@ -1104,9 +1095,6 @@
 strstream limits
 strstream locale
 strstream new
-strstream optional
-strstream ostream
-strstream print
 strstream ratio
 strstream stdexcept
 strstream streambuf
diff --git a/test/std/input.output/file.streams/fstreams/native_handle_test_helpers.h b/test/std/input.output/file.streams/fstreams/native_handle_test_helpers.h
index 4bc862d..9cafec5 100644
--- a/test/std/input.output/file.streams/fstreams/native_handle_test_helpers.h
+++ b/test/std/input.output/file.streams/fstreams/native_handle_test_helpers.h
@@ -10,6 +10,7 @@
 #define TEST_STD_INPUT_OUTPUT_FILE_STREAMS_FSTREAMS_TEST_HELPERS_H
 
 #include <cassert>
+#include <cerrno>
 #include <concepts>
 #include <cstdio>
 #include <fstream>