1// -*- C++ -*- 2//===----------------------------------------------------------------------===// 3// 4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 5// See https://llvm.org/LICENSE.txt for license information. 6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 7// 8//===----------------------------------------------------------------------===// 9 10#ifndef _LIBCPP_FSTREAM 11#define _LIBCPP_FSTREAM 12 13/* 14 fstream synopsis 15 16template <class charT, class traits = char_traits<charT> > 17class basic_filebuf 18 : public basic_streambuf<charT, traits> 19{ 20public: 21 typedef charT char_type; 22 typedef traits traits_type; 23 typedef typename traits_type::int_type int_type; 24 typedef typename traits_type::pos_type pos_type; 25 typedef typename traits_type::off_type off_type; 26 27 // 27.9.1.2 Constructors/destructor: 28 basic_filebuf(); 29 basic_filebuf(basic_filebuf&& rhs); 30 virtual ~basic_filebuf(); 31 32 // 27.9.1.3 Assign/swap: 33 basic_filebuf& operator=(basic_filebuf&& rhs); 34 void swap(basic_filebuf& rhs); 35 36 // 27.9.1.4 Members: 37 bool is_open() const; 38 basic_filebuf* open(const char* s, ios_base::openmode mode); 39 basic_filebuf* open(const string& s, ios_base::openmode mode); 40 basic_filebuf* open(const filesystem::path& p, ios_base::openmode mode); // C++17 41 basic_filebuf* close(); 42 43protected: 44 // 27.9.1.5 Overridden virtual functions: 45 virtual streamsize showmanyc(); 46 virtual int_type underflow(); 47 virtual int_type uflow(); 48 virtual int_type pbackfail(int_type c = traits_type::eof()); 49 virtual int_type overflow (int_type c = traits_type::eof()); 50 virtual basic_streambuf<char_type, traits_type>* setbuf(char_type* s, streamsize n); 51 virtual pos_type seekoff(off_type off, ios_base::seekdir way, 52 ios_base::openmode which = ios_base::in | ios_base::out); 53 virtual pos_type seekpos(pos_type sp, 54 ios_base::openmode which = ios_base::in | ios_base::out); 55 virtual int sync(); 56 virtual void imbue(const locale& loc); 57}; 58 59template <class charT, class traits> 60 void 61 swap(basic_filebuf<charT, traits>& x, basic_filebuf<charT, traits>& y); 62 63typedef basic_filebuf<char> filebuf; 64typedef basic_filebuf<wchar_t> wfilebuf; 65 66template <class charT, class traits = char_traits<charT> > 67class basic_ifstream 68 : public basic_istream<charT,traits> 69{ 70public: 71 typedef charT char_type; 72 typedef traits traits_type; 73 typedef typename traits_type::int_type int_type; 74 typedef typename traits_type::pos_type pos_type; 75 typedef typename traits_type::off_type off_type; 76 using native_handle_type = typename basic_filebuf<charT, traits>::native_handle_type; // Since C++26 77 78 basic_ifstream(); 79 explicit basic_ifstream(const char* s, ios_base::openmode mode = ios_base::in); 80 explicit basic_ifstream(const string& s, ios_base::openmode mode = ios_base::in); 81 template<class T> 82 explicit basic_ifstream(const T& s, ios_base::openmode mode = ios_base::in); // Since C++17 83 basic_ifstream(basic_ifstream&& rhs); 84 85 basic_ifstream& operator=(basic_ifstream&& rhs); 86 void swap(basic_ifstream& rhs); 87 88 basic_filebuf<char_type, traits_type>* rdbuf() const; 89 native_handle_type native_handle() const noexcept; // Since C++26 90 bool is_open() const; 91 void open(const char* s, ios_base::openmode mode = ios_base::in); 92 void open(const string& s, ios_base::openmode mode = ios_base::in); 93 void open(const filesystem::path& s, ios_base::openmode mode = ios_base::in); // C++17 94 95 void close(); 96}; 97 98template <class charT, class traits> 99 void 100 swap(basic_ifstream<charT, traits>& x, basic_ifstream<charT, traits>& y); 101 102typedef basic_ifstream<char> ifstream; 103typedef basic_ifstream<wchar_t> wifstream; 104 105template <class charT, class traits = char_traits<charT> > 106class basic_ofstream 107 : public basic_ostream<charT,traits> 108{ 109public: 110 typedef charT char_type; 111 typedef traits traits_type; 112 typedef typename traits_type::int_type int_type; 113 typedef typename traits_type::pos_type pos_type; 114 typedef typename traits_type::off_type off_type; 115 using native_handle_type = typename basic_filebuf<charT, traits>::native_handle_type; // Since C++26 116 117 basic_ofstream(); 118 explicit basic_ofstream(const char* s, ios_base::openmode mode = ios_base::out); 119 explicit basic_ofstream(const string& s, ios_base::openmode mode = ios_base::out); 120 template<class T> 121 explicit basic_ofstream(const T& s, ios_base::openmode mode = ios_base::out); // Since C++17 122 basic_ofstream(basic_ofstream&& rhs); 123 124 basic_ofstream& operator=(basic_ofstream&& rhs); 125 void swap(basic_ofstream& rhs); 126 127 basic_filebuf<char_type, traits_type>* rdbuf() const; 128 native_handle_type native_handle() const noexcept; // Since C++26 129 130 bool is_open() const; 131 void open(const char* s, ios_base::openmode mode = ios_base::out); 132 void open(const string& s, ios_base::openmode mode = ios_base::out); 133 void open(const filesystem::path& p, 134 ios_base::openmode mode = ios_base::out); // C++17 135 136 void close(); 137}; 138 139template <class charT, class traits> 140 void 141 swap(basic_ofstream<charT, traits>& x, basic_ofstream<charT, traits>& y); 142 143typedef basic_ofstream<char> ofstream; 144typedef basic_ofstream<wchar_t> wofstream; 145 146template <class charT, class traits=char_traits<charT> > 147class basic_fstream 148 : public basic_iostream<charT,traits> 149{ 150public: 151 typedef charT char_type; 152 typedef traits traits_type; 153 typedef typename traits_type::int_type int_type; 154 typedef typename traits_type::pos_type pos_type; 155 typedef typename traits_type::off_type off_type; 156 using native_handle_type = typename basic_filebuf<charT, traits>::native_handle_type; // Since C++26 157 158 basic_fstream(); 159 explicit basic_fstream(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out); 160 explicit basic_fstream(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out); 161 template<class T> 162 explicit basic_fstream(const T& s, ios_base::openmode mode = ios_base::in | ios_base::out); // Since C++17 163 basic_fstream(basic_fstream&& rhs); 164 165 basic_fstream& operator=(basic_fstream&& rhs); 166 void swap(basic_fstream& rhs); 167 168 basic_filebuf<char_type, traits_type>* rdbuf() const; 169 native_handle_type native_handle() const noexcept; // Since C++26 170 bool is_open() const; 171 void open(const char* s, ios_base::openmode mode = ios_base::in|ios_base::out); 172 void open(const string& s, ios_base::openmode mode = ios_base::in|ios_base::out); 173 void open(const filesystem::path& s, 174 ios_base::openmode mode = ios_base::in|ios_base::out); // C++17 175 176 void close(); 177}; 178 179template <class charT, class traits> 180 void swap(basic_fstream<charT, traits>& x, basic_fstream<charT, traits>& y); 181 182typedef basic_fstream<char> fstream; 183typedef basic_fstream<wchar_t> wfstream; 184 185} // std 186 187*/ 188 189#include <__algorithm/max.h> 190#include <__assert> 191#include <__config> 192#include <__fwd/fstream.h> 193#include <__locale> 194#include <__memory/addressof.h> 195#include <__type_traits/enable_if.h> 196#include <__type_traits/is_same.h> 197#include <__utility/move.h> 198#include <__utility/swap.h> 199#include <__utility/unreachable.h> 200#include <cstdio> 201#include <filesystem> 202#include <istream> 203#include <ostream> 204#include <typeinfo> 205#include <version> 206 207#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 208# pragma GCC system_header 209#endif 210 211_LIBCPP_PUSH_MACROS 212#include <__undef_macros> 213 214#if defined(_LIBCPP_MSVCRT) || defined(_NEWLIB_VERSION) 215# define _LIBCPP_HAS_NO_OFF_T_FUNCTIONS 216#endif 217 218#if !defined(_LIBCPP_HAS_NO_FILESYSTEM) 219 220_LIBCPP_BEGIN_NAMESPACE_STD 221 222# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_WIN32API) 223_LIBCPP_EXPORTED_FROM_ABI void* __filebuf_windows_native_handle(FILE* __file) noexcept; 224# endif 225 226template <class _CharT, class _Traits> 227class _LIBCPP_TEMPLATE_VIS basic_filebuf : public basic_streambuf<_CharT, _Traits> { 228public: 229 typedef _CharT char_type; 230 typedef _Traits traits_type; 231 typedef typename traits_type::int_type int_type; 232 typedef typename traits_type::pos_type pos_type; 233 typedef typename traits_type::off_type off_type; 234 typedef typename traits_type::state_type state_type; 235# if _LIBCPP_STD_VER >= 26 236# if defined(_LIBCPP_WIN32API) 237 using native_handle_type = void*; // HANDLE 238# elif __has_include(<unistd.h>) 239 using native_handle_type = int; // POSIX file descriptor 240# else 241# error "Provide a native file handle!" 242# endif 243# endif 244 245 // 27.9.1.2 Constructors/destructor: 246 basic_filebuf(); 247 basic_filebuf(basic_filebuf&& __rhs); 248 ~basic_filebuf() override; 249 250 // 27.9.1.3 Assign/swap: 251 _LIBCPP_HIDE_FROM_ABI basic_filebuf& operator=(basic_filebuf&& __rhs); 252 void swap(basic_filebuf& __rhs); 253 254 // 27.9.1.4 Members: 255 _LIBCPP_HIDE_FROM_ABI bool is_open() const; 256 basic_filebuf* open(const char* __s, ios_base::openmode __mode); 257# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 258 basic_filebuf* open(const wchar_t* __s, ios_base::openmode __mode); 259# endif 260 _LIBCPP_HIDE_FROM_ABI basic_filebuf* open(const string& __s, ios_base::openmode __mode); 261 262# if _LIBCPP_STD_VER >= 17 263 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI basic_filebuf* 264 open(const filesystem::path& __p, ios_base::openmode __mode) { 265 return open(__p.c_str(), __mode); 266 } 267# endif 268 _LIBCPP_HIDE_FROM_ABI basic_filebuf* __open(int __fd, ios_base::openmode __mode); 269 basic_filebuf* close(); 270# if _LIBCPP_STD_VER >= 26 271 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { 272 _LIBCPP_ASSERT_UNCATEGORIZED(this->is_open(), "File must be opened"); 273# if defined(_LIBCPP_WIN32API) 274 return std::__filebuf_windows_native_handle(__file_); 275# elif __has_include(<unistd.h>) 276 return fileno(__file_); 277# else 278# error "Provide a way to determine the file native handle!" 279# endif 280 } 281# endif // _LIBCPP_STD_VER >= 26 282 283 _LIBCPP_HIDE_FROM_ABI inline static const char* __make_mdstring(ios_base::openmode __mode) _NOEXCEPT; 284# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 285 _LIBCPP_HIDE_FROM_ABI inline static const wchar_t* __make_mdwstring(ios_base::openmode __mode) _NOEXCEPT; 286# endif 287 288protected: 289 // 27.9.1.5 Overridden virtual functions: 290 int_type underflow() override; 291 int_type pbackfail(int_type __c = traits_type::eof()) override; 292 int_type overflow(int_type __c = traits_type::eof()) override; 293 basic_streambuf<char_type, traits_type>* setbuf(char_type* __s, streamsize __n) override; 294 pos_type 295 seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __wch = ios_base::in | ios_base::out) override; 296 pos_type seekpos(pos_type __sp, ios_base::openmode __wch = ios_base::in | ios_base::out) override; 297 int sync() override; 298 void imbue(const locale& __loc) override; 299 300private: 301 char* __extbuf_; 302 const char* __extbufnext_; 303 const char* __extbufend_; 304 char __extbuf_min_[8]; 305 size_t __ebs_; 306 char_type* __intbuf_; 307 size_t __ibs_; 308 FILE* __file_; 309 const codecvt<char_type, char, state_type>* __cv_; 310 state_type __st_; 311 state_type __st_last_; 312 ios_base::openmode __om_; 313 // There have been no file operations yet, which allows setting unbuffered 314 // I/O mode. 315 static const ios_base::openmode __no_io_operations = ios_base::trunc; 316 // Unbuffered I/O mode has been requested. 317 static const ios_base::openmode __use_unbuffered_io = ios_base::ate; 318 // Used to track the currently used mode and track whether the output should 319 // be unbuffered. 320 // [filebuf.virtuals]/12 321 // If setbuf(0, 0) is called on a stream before any I/O has occurred on 322 // that stream, the stream becomes unbuffered. Otherwise the results are 323 // implementation-defined. 324 // This allows calling setbuf(0, 0) 325 // - before opening a file, 326 // - after opening a file, before 327 // - a read 328 // - a write 329 // - a seek. 330 // Note that opening a file with ios_base::ate does a seek operation. 331 // Normally underflow, overflow, and sync change this flag to ios_base::in, 332 // ios_base_out, or 0. 333 // 334 // The ios_base::trunc and ios_base::ate flags are not used in __cm_. They 335 // are used to track the state of the unbuffered request. For readability 336 // they have the aliases __no_io_operations and __use_unbuffered_io 337 // respectively. 338 // 339 // The __no_io_operations and __use_unbuffered_io flags are used in the 340 // following way: 341 // - __no_io_operations is set upon construction to indicate the unbuffered 342 // state can be set. 343 // - When requesting unbuffered output: 344 // - If the file is open it sets the mode. 345 // - Else places a request by adding the __use_unbuffered_io flag. 346 // - When a file is opened it checks whether both __no_io_operations and 347 // __use_unbuffered_io are set. If so switches to unbuffered mode. 348 // - All file I/O operations change the mode effectively clearing the 349 // __no_io_operations and __use_unbuffered_io flags. 350 ios_base::openmode __cm_; 351 bool __owns_eb_; 352 bool __owns_ib_; 353 bool __always_noconv_; 354 355 bool __read_mode(); 356 void __write_mode(); 357 358 _LIBCPP_EXPORTED_FROM_ABI friend FILE* __get_ostream_file(ostream&); 359 360 // There are multiple (__)open function, they use different C-API open 361 // function. After that call these functions behave the same. This function 362 // does that part and determines the final return value. 363 _LIBCPP_HIDE_FROM_ABI basic_filebuf* __do_open(FILE* __file, ios_base::openmode __mode) { 364 __file_ = __file; 365 if (!__file_) 366 return nullptr; 367 368 __om_ = __mode; 369 if (__cm_ == (__no_io_operations | __use_unbuffered_io)) { 370 std::setbuf(__file_, nullptr); 371 __cm_ = 0; 372 } 373 374 if (__mode & ios_base::ate) { 375 __cm_ = 0; 376 if (fseek(__file_, 0, SEEK_END)) { 377 fclose(__file_); 378 __file_ = nullptr; 379 return nullptr; 380 } 381 } 382 383 return this; 384 } 385 386 // If the file is already open, switch to unbuffered mode. Otherwise, record 387 // the request to use unbuffered mode so that we use that mode when we 388 // eventually open the file. 389 _LIBCPP_HIDE_FROM_ABI void __request_unbuffered_mode(char_type* __s, streamsize __n) { 390 if (__cm_ == __no_io_operations && __s == nullptr && __n == 0) { 391 if (__file_) { 392 std::setbuf(__file_, nullptr); 393 __cm_ = 0; 394 } else { 395 __cm_ = __no_io_operations | __use_unbuffered_io; 396 } 397 } 398 } 399}; 400 401template <class _CharT, class _Traits> 402basic_filebuf<_CharT, _Traits>::basic_filebuf() 403 : __extbuf_(nullptr), 404 __extbufnext_(nullptr), 405 __extbufend_(nullptr), 406 __ebs_(0), 407 __intbuf_(nullptr), 408 __ibs_(0), 409 __file_(nullptr), 410 __cv_(nullptr), 411 __st_(), 412 __st_last_(), 413 __om_(0), 414 __cm_(__no_io_operations), 415 __owns_eb_(false), 416 __owns_ib_(false), 417 __always_noconv_(false) { 418 if (std::has_facet<codecvt<char_type, char, state_type> >(this->getloc())) { 419 __cv_ = &std::use_facet<codecvt<char_type, char, state_type> >(this->getloc()); 420 __always_noconv_ = __cv_->always_noconv(); 421 } 422 setbuf(nullptr, 4096); 423} 424 425template <class _CharT, class _Traits> 426basic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs) : basic_streambuf<_CharT, _Traits>(__rhs) { 427 if (__rhs.__extbuf_ == __rhs.__extbuf_min_) { 428 __extbuf_ = __extbuf_min_; 429 __extbufnext_ = __extbuf_ + (__rhs.__extbufnext_ - __rhs.__extbuf_); 430 __extbufend_ = __extbuf_ + (__rhs.__extbufend_ - __rhs.__extbuf_); 431 } else { 432 __extbuf_ = __rhs.__extbuf_; 433 __extbufnext_ = __rhs.__extbufnext_; 434 __extbufend_ = __rhs.__extbufend_; 435 } 436 __ebs_ = __rhs.__ebs_; 437 __intbuf_ = __rhs.__intbuf_; 438 __ibs_ = __rhs.__ibs_; 439 __file_ = __rhs.__file_; 440 __cv_ = __rhs.__cv_; 441 __st_ = __rhs.__st_; 442 __st_last_ = __rhs.__st_last_; 443 __om_ = __rhs.__om_; 444 __cm_ = __rhs.__cm_; 445 __owns_eb_ = __rhs.__owns_eb_; 446 __owns_ib_ = __rhs.__owns_ib_; 447 __always_noconv_ = __rhs.__always_noconv_; 448 if (__rhs.pbase()) { 449 if (__rhs.pbase() == __rhs.__intbuf_) 450 this->setp(__intbuf_, __intbuf_ + (__rhs.epptr() - __rhs.pbase())); 451 else 452 this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__rhs.epptr() - __rhs.pbase())); 453 this->__pbump(__rhs.pptr() - __rhs.pbase()); 454 } else if (__rhs.eback()) { 455 if (__rhs.eback() == __rhs.__intbuf_) 456 this->setg(__intbuf_, __intbuf_ + (__rhs.gptr() - __rhs.eback()), __intbuf_ + (__rhs.egptr() - __rhs.eback())); 457 else 458 this->setg((char_type*)__extbuf_, 459 (char_type*)__extbuf_ + (__rhs.gptr() - __rhs.eback()), 460 (char_type*)__extbuf_ + (__rhs.egptr() - __rhs.eback())); 461 } 462 __rhs.__extbuf_ = nullptr; 463 __rhs.__extbufnext_ = nullptr; 464 __rhs.__extbufend_ = nullptr; 465 __rhs.__ebs_ = 0; 466 __rhs.__intbuf_ = 0; 467 __rhs.__ibs_ = 0; 468 __rhs.__file_ = nullptr; 469 __rhs.__st_ = state_type(); 470 __rhs.__st_last_ = state_type(); 471 __rhs.__om_ = 0; 472 __rhs.__cm_ = 0; 473 __rhs.__owns_eb_ = false; 474 __rhs.__owns_ib_ = false; 475 __rhs.setg(0, 0, 0); 476 __rhs.setp(0, 0); 477} 478 479template <class _CharT, class _Traits> 480inline basic_filebuf<_CharT, _Traits>& basic_filebuf<_CharT, _Traits>::operator=(basic_filebuf&& __rhs) { 481 close(); 482 swap(__rhs); 483 return *this; 484} 485 486template <class _CharT, class _Traits> 487basic_filebuf<_CharT, _Traits>::~basic_filebuf() { 488# ifndef _LIBCPP_HAS_NO_EXCEPTIONS 489 try { 490# endif // _LIBCPP_HAS_NO_EXCEPTIONS 491 close(); 492# ifndef _LIBCPP_HAS_NO_EXCEPTIONS 493 } catch (...) { 494 } 495# endif // _LIBCPP_HAS_NO_EXCEPTIONS 496 if (__owns_eb_) 497 delete[] __extbuf_; 498 if (__owns_ib_) 499 delete[] __intbuf_; 500} 501 502template <class _CharT, class _Traits> 503void basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs) { 504 basic_streambuf<char_type, traits_type>::swap(__rhs); 505 if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) { 506 // Neither *this nor __rhs uses the small buffer, so we can simply swap the pointers. 507 std::swap(__extbuf_, __rhs.__extbuf_); 508 std::swap(__extbufnext_, __rhs.__extbufnext_); 509 std::swap(__extbufend_, __rhs.__extbufend_); 510 } else { 511 ptrdiff_t __ln = __extbufnext_ ? __extbufnext_ - __extbuf_ : 0; 512 ptrdiff_t __le = __extbufend_ ? __extbufend_ - __extbuf_ : 0; 513 ptrdiff_t __rn = __rhs.__extbufnext_ ? __rhs.__extbufnext_ - __rhs.__extbuf_ : 0; 514 ptrdiff_t __re = __rhs.__extbufend_ ? __rhs.__extbufend_ - __rhs.__extbuf_ : 0; 515 if (__extbuf_ == __extbuf_min_ && __rhs.__extbuf_ != __rhs.__extbuf_min_) { 516 // *this uses the small buffer, but __rhs doesn't. 517 __extbuf_ = __rhs.__extbuf_; 518 __rhs.__extbuf_ = __rhs.__extbuf_min_; 519 std::memmove(__rhs.__extbuf_min_, __extbuf_min_, sizeof(__extbuf_min_)); 520 } else if (__extbuf_ != __extbuf_min_ && __rhs.__extbuf_ == __rhs.__extbuf_min_) { 521 // *this doesn't use the small buffer, but __rhs does. 522 __rhs.__extbuf_ = __extbuf_; 523 __extbuf_ = __extbuf_min_; 524 std::memmove(__extbuf_min_, __rhs.__extbuf_min_, sizeof(__extbuf_min_)); 525 } else { 526 // Both *this and __rhs use the small buffer. 527 char __tmp[sizeof(__extbuf_min_)]; 528 std::memmove(__tmp, __extbuf_min_, sizeof(__extbuf_min_)); 529 std::memmove(__extbuf_min_, __rhs.__extbuf_min_, sizeof(__extbuf_min_)); 530 std::memmove(__rhs.__extbuf_min_, __tmp, sizeof(__extbuf_min_)); 531 } 532 __extbufnext_ = __extbuf_ + __rn; 533 __extbufend_ = __extbuf_ + __re; 534 __rhs.__extbufnext_ = __rhs.__extbuf_ + __ln; 535 __rhs.__extbufend_ = __rhs.__extbuf_ + __le; 536 } 537 std::swap(__ebs_, __rhs.__ebs_); 538 std::swap(__intbuf_, __rhs.__intbuf_); 539 std::swap(__ibs_, __rhs.__ibs_); 540 std::swap(__file_, __rhs.__file_); 541 std::swap(__cv_, __rhs.__cv_); 542 std::swap(__st_, __rhs.__st_); 543 std::swap(__st_last_, __rhs.__st_last_); 544 std::swap(__om_, __rhs.__om_); 545 std::swap(__cm_, __rhs.__cm_); 546 std::swap(__owns_eb_, __rhs.__owns_eb_); 547 std::swap(__owns_ib_, __rhs.__owns_ib_); 548 std::swap(__always_noconv_, __rhs.__always_noconv_); 549 if (this->eback() == (char_type*)__rhs.__extbuf_min_) { 550 ptrdiff_t __n = this->gptr() - this->eback(); 551 ptrdiff_t __e = this->egptr() - this->eback(); 552 this->setg((char_type*)__extbuf_min_, (char_type*)__extbuf_min_ + __n, (char_type*)__extbuf_min_ + __e); 553 } else if (this->pbase() == (char_type*)__rhs.__extbuf_min_) { 554 ptrdiff_t __n = this->pptr() - this->pbase(); 555 ptrdiff_t __e = this->epptr() - this->pbase(); 556 this->setp((char_type*)__extbuf_min_, (char_type*)__extbuf_min_ + __e); 557 this->__pbump(__n); 558 } 559 if (__rhs.eback() == (char_type*)__extbuf_min_) { 560 ptrdiff_t __n = __rhs.gptr() - __rhs.eback(); 561 ptrdiff_t __e = __rhs.egptr() - __rhs.eback(); 562 __rhs.setg( 563 (char_type*)__rhs.__extbuf_min_, (char_type*)__rhs.__extbuf_min_ + __n, (char_type*)__rhs.__extbuf_min_ + __e); 564 } else if (__rhs.pbase() == (char_type*)__extbuf_min_) { 565 ptrdiff_t __n = __rhs.pptr() - __rhs.pbase(); 566 ptrdiff_t __e = __rhs.epptr() - __rhs.pbase(); 567 __rhs.setp((char_type*)__rhs.__extbuf_min_, (char_type*)__rhs.__extbuf_min_ + __e); 568 __rhs.__pbump(__n); 569 } 570} 571 572template <class _CharT, class _Traits> 573inline _LIBCPP_HIDE_FROM_ABI void swap(basic_filebuf<_CharT, _Traits>& __x, basic_filebuf<_CharT, _Traits>& __y) { 574 __x.swap(__y); 575} 576 577template <class _CharT, class _Traits> 578inline bool basic_filebuf<_CharT, _Traits>::is_open() const { 579 return __file_ != nullptr; 580} 581 582template <class _CharT, class _Traits> 583const char* basic_filebuf<_CharT, _Traits>::__make_mdstring(ios_base::openmode __mode) _NOEXCEPT { 584 switch (__mode & ~ios_base::ate) { 585 case ios_base::out: 586 case ios_base::out | ios_base::trunc: 587 return "w" _LIBCPP_FOPEN_CLOEXEC_MODE; 588 case ios_base::out | ios_base::app: 589 case ios_base::app: 590 return "a" _LIBCPP_FOPEN_CLOEXEC_MODE; 591 case ios_base::in: 592 return "r" _LIBCPP_FOPEN_CLOEXEC_MODE; 593 case ios_base::in | ios_base::out: 594 return "r+" _LIBCPP_FOPEN_CLOEXEC_MODE; 595 case ios_base::in | ios_base::out | ios_base::trunc: 596 return "w+" _LIBCPP_FOPEN_CLOEXEC_MODE; 597 case ios_base::in | ios_base::out | ios_base::app: 598 case ios_base::in | ios_base::app: 599 return "a+" _LIBCPP_FOPEN_CLOEXEC_MODE; 600 case ios_base::out | ios_base::binary: 601 case ios_base::out | ios_base::trunc | ios_base::binary: 602 return "wb" _LIBCPP_FOPEN_CLOEXEC_MODE; 603 case ios_base::out | ios_base::app | ios_base::binary: 604 case ios_base::app | ios_base::binary: 605 return "ab" _LIBCPP_FOPEN_CLOEXEC_MODE; 606 case ios_base::in | ios_base::binary: 607 return "rb" _LIBCPP_FOPEN_CLOEXEC_MODE; 608 case ios_base::in | ios_base::out | ios_base::binary: 609 return "r+b" _LIBCPP_FOPEN_CLOEXEC_MODE; 610 case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary: 611 return "w+b" _LIBCPP_FOPEN_CLOEXEC_MODE; 612 case ios_base::in | ios_base::out | ios_base::app | ios_base::binary: 613 case ios_base::in | ios_base::app | ios_base::binary: 614 return "a+b" _LIBCPP_FOPEN_CLOEXEC_MODE; 615# if _LIBCPP_STD_VER >= 23 616 case ios_base::out | ios_base::noreplace: 617 case ios_base::out | ios_base::trunc | ios_base::noreplace: 618 return "wx" _LIBCPP_FOPEN_CLOEXEC_MODE; 619 case ios_base::in | ios_base::out | ios_base::trunc | ios_base::noreplace: 620 return "w+x" _LIBCPP_FOPEN_CLOEXEC_MODE; 621 case ios_base::out | ios_base::binary | ios_base::noreplace: 622 case ios_base::out | ios_base::trunc | ios_base::binary | ios_base::noreplace: 623 return "wbx" _LIBCPP_FOPEN_CLOEXEC_MODE; 624 case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary | ios_base::noreplace: 625 return "w+bx" _LIBCPP_FOPEN_CLOEXEC_MODE; 626# endif // _LIBCPP_STD_VER >= 23 627 default: 628 return nullptr; 629 } 630 __libcpp_unreachable(); 631} 632 633# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 634template <class _CharT, class _Traits> 635const wchar_t* basic_filebuf<_CharT, _Traits>::__make_mdwstring(ios_base::openmode __mode) _NOEXCEPT { 636 switch (__mode & ~ios_base::ate) { 637 case ios_base::out: 638 case ios_base::out | ios_base::trunc: 639 return L"w"; 640 case ios_base::out | ios_base::app: 641 case ios_base::app: 642 return L"a"; 643 case ios_base::in: 644 return L"r"; 645 case ios_base::in | ios_base::out: 646 return L"r+"; 647 case ios_base::in | ios_base::out | ios_base::trunc: 648 return L"w+"; 649 case ios_base::in | ios_base::out | ios_base::app: 650 case ios_base::in | ios_base::app: 651 return L"a+"; 652 case ios_base::out | ios_base::binary: 653 case ios_base::out | ios_base::trunc | ios_base::binary: 654 return L"wb"; 655 case ios_base::out | ios_base::app | ios_base::binary: 656 case ios_base::app | ios_base::binary: 657 return L"ab"; 658 case ios_base::in | ios_base::binary: 659 return L"rb"; 660 case ios_base::in | ios_base::out | ios_base::binary: 661 return L"r+b"; 662 case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary: 663 return L"w+b"; 664 case ios_base::in | ios_base::out | ios_base::app | ios_base::binary: 665 case ios_base::in | ios_base::app | ios_base::binary: 666 return L"a+b"; 667# if _LIBCPP_STD_VER >= 23 668 case ios_base::out | ios_base::noreplace: 669 case ios_base::out | ios_base::trunc | ios_base::noreplace: 670 return L"wx"; 671 case ios_base::in | ios_base::out | ios_base::trunc | ios_base::noreplace: 672 return L"w+x"; 673 case ios_base::out | ios_base::binary | ios_base::noreplace: 674 case ios_base::out | ios_base::trunc | ios_base::binary | ios_base::noreplace: 675 return L"wbx"; 676 case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary | ios_base::noreplace: 677 return L"w+bx"; 678# endif // _LIBCPP_STD_VER >= 23 679 default: 680 return nullptr; 681 } 682 __libcpp_unreachable(); 683} 684# endif 685 686template <class _CharT, class _Traits> 687basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) { 688 if (__file_) 689 return nullptr; 690 const char* __mdstr = __make_mdstring(__mode); 691 if (!__mdstr) 692 return nullptr; 693 694 return __do_open(fopen(__s, __mdstr), __mode); 695} 696 697template <class _CharT, class _Traits> 698inline basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::__open(int __fd, ios_base::openmode __mode) { 699 if (__file_) 700 return nullptr; 701 const char* __mdstr = __make_mdstring(__mode); 702 if (!__mdstr) 703 return nullptr; 704 705 return __do_open(fdopen(__fd, __mdstr), __mode); 706} 707 708# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 709// This is basically the same as the char* overload except that it uses _wfopen 710// and long mode strings. 711template <class _CharT, class _Traits> 712basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) { 713 if (__file_) 714 return nullptr; 715 const wchar_t* __mdstr = __make_mdwstring(__mode); 716 if (!__mdstr) 717 return nullptr; 718 719 return __do_open(_wfopen(__s, __mdstr), __mode); 720} 721# endif 722 723template <class _CharT, class _Traits> 724inline basic_filebuf<_CharT, _Traits>* 725basic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) { 726 return open(__s.c_str(), __mode); 727} 728 729template <class _CharT, class _Traits> 730basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::close() { 731 basic_filebuf<_CharT, _Traits>* __rt = nullptr; 732 if (__file_) { 733 __rt = this; 734 unique_ptr<FILE, int (*)(FILE*)> __h(__file_, fclose); 735 if (sync()) 736 __rt = nullptr; 737 if (fclose(__h.release())) 738 __rt = nullptr; 739 __file_ = nullptr; 740 setbuf(0, 0); 741 } 742 return __rt; 743} 744 745template <class _CharT, class _Traits> 746typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::underflow() { 747 if (__file_ == nullptr) 748 return traits_type::eof(); 749 bool __initial = __read_mode(); 750 char_type __1buf; 751 if (this->gptr() == nullptr) 752 this->setg(&__1buf, &__1buf + 1, &__1buf + 1); 753 const size_t __unget_sz = __initial ? 0 : std::min<size_t>((this->egptr() - this->eback()) / 2, 4); 754 int_type __c = traits_type::eof(); 755 if (this->gptr() == this->egptr()) { 756 std::memmove(this->eback(), this->egptr() - __unget_sz, __unget_sz * sizeof(char_type)); 757 if (__always_noconv_) { 758 size_t __nmemb = static_cast<size_t>(this->egptr() - this->eback() - __unget_sz); 759 __nmemb = ::fread(this->eback() + __unget_sz, 1, __nmemb, __file_); 760 if (__nmemb != 0) { 761 this->setg(this->eback(), this->eback() + __unget_sz, this->eback() + __unget_sz + __nmemb); 762 __c = traits_type::to_int_type(*this->gptr()); 763 } 764 } else { 765 if (__extbufend_ != __extbufnext_) { 766 _LIBCPP_ASSERT_NON_NULL(__extbufnext_ != nullptr, "underflow moving from nullptr"); 767 _LIBCPP_ASSERT_NON_NULL(__extbuf_ != nullptr, "underflow moving into nullptr"); 768 std::memmove(__extbuf_, __extbufnext_, __extbufend_ - __extbufnext_); 769 } 770 __extbufnext_ = __extbuf_ + (__extbufend_ - __extbufnext_); 771 __extbufend_ = __extbuf_ + (__extbuf_ == __extbuf_min_ ? sizeof(__extbuf_min_) : __ebs_); 772 size_t __nmemb = 773 std::min(static_cast<size_t>(__ibs_ - __unget_sz), static_cast<size_t>(__extbufend_ - __extbufnext_)); 774 codecvt_base::result __r; 775 __st_last_ = __st_; 776 size_t __nr = fread((void*)const_cast<char*>(__extbufnext_), 1, __nmemb, __file_); 777 if (__nr != 0) { 778 if (!__cv_) 779 __throw_bad_cast(); 780 781 __extbufend_ = __extbufnext_ + __nr; 782 char_type* __inext; 783 __r = __cv_->in( 784 __st_, __extbuf_, __extbufend_, __extbufnext_, this->eback() + __unget_sz, this->eback() + __ibs_, __inext); 785 if (__r == codecvt_base::noconv) { 786 this->setg((char_type*)__extbuf_, (char_type*)__extbuf_, (char_type*)const_cast<char*>(__extbufend_)); 787 __c = traits_type::to_int_type(*this->gptr()); 788 } else if (__inext != this->eback() + __unget_sz) { 789 this->setg(this->eback(), this->eback() + __unget_sz, __inext); 790 __c = traits_type::to_int_type(*this->gptr()); 791 } 792 } 793 } 794 } else 795 __c = traits_type::to_int_type(*this->gptr()); 796 if (this->eback() == &__1buf) 797 this->setg(nullptr, nullptr, nullptr); 798 return __c; 799} 800 801template <class _CharT, class _Traits> 802typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::pbackfail(int_type __c) { 803 if (__file_ && this->eback() < this->gptr()) { 804 if (traits_type::eq_int_type(__c, traits_type::eof())) { 805 this->gbump(-1); 806 return traits_type::not_eof(__c); 807 } 808 if ((__om_ & ios_base::out) || traits_type::eq(traits_type::to_char_type(__c), this->gptr()[-1])) { 809 this->gbump(-1); 810 *this->gptr() = traits_type::to_char_type(__c); 811 return __c; 812 } 813 } 814 return traits_type::eof(); 815} 816 817template <class _CharT, class _Traits> 818typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::overflow(int_type __c) { 819 if (__file_ == nullptr) 820 return traits_type::eof(); 821 __write_mode(); 822 char_type __1buf; 823 char_type* __pb_save = this->pbase(); 824 char_type* __epb_save = this->epptr(); 825 if (!traits_type::eq_int_type(__c, traits_type::eof())) { 826 if (this->pptr() == nullptr) 827 this->setp(&__1buf, &__1buf + 1); 828 *this->pptr() = traits_type::to_char_type(__c); 829 this->pbump(1); 830 } 831 if (this->pptr() != this->pbase()) { 832 if (__always_noconv_) { 833 size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase()); 834 if (std::fwrite(this->pbase(), sizeof(char_type), __nmemb, __file_) != __nmemb) 835 return traits_type::eof(); 836 } else { 837 char* __extbe = __extbuf_; 838 codecvt_base::result __r; 839 do { 840 if (!__cv_) 841 __throw_bad_cast(); 842 843 const char_type* __e; 844 __r = __cv_->out(__st_, this->pbase(), this->pptr(), __e, __extbuf_, __extbuf_ + __ebs_, __extbe); 845 if (__e == this->pbase()) 846 return traits_type::eof(); 847 if (__r == codecvt_base::noconv) { 848 size_t __nmemb = static_cast<size_t>(this->pptr() - this->pbase()); 849 if (std::fwrite(this->pbase(), 1, __nmemb, __file_) != __nmemb) 850 return traits_type::eof(); 851 } else if (__r == codecvt_base::ok || __r == codecvt_base::partial) { 852 size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_); 853 if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb) 854 return traits_type::eof(); 855 if (__r == codecvt_base::partial) { 856 this->setp(const_cast<char_type*>(__e), this->pptr()); 857 this->__pbump(this->epptr() - this->pbase()); 858 } 859 } else 860 return traits_type::eof(); 861 } while (__r == codecvt_base::partial); 862 } 863 this->setp(__pb_save, __epb_save); 864 } 865 return traits_type::not_eof(__c); 866} 867 868template <class _CharT, class _Traits> 869basic_streambuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::setbuf(char_type* __s, streamsize __n) { 870 this->setg(nullptr, nullptr, nullptr); 871 this->setp(nullptr, nullptr); 872 __request_unbuffered_mode(__s, __n); 873 if (__owns_eb_) 874 delete[] __extbuf_; 875 if (__owns_ib_) 876 delete[] __intbuf_; 877 __ebs_ = __n; 878 if (__ebs_ > sizeof(__extbuf_min_)) { 879 if (__always_noconv_ && __s) { 880 __extbuf_ = (char*)__s; 881 __owns_eb_ = false; 882 } else { 883 __extbuf_ = new char[__ebs_]; 884 __owns_eb_ = true; 885 } 886 } else { 887 __extbuf_ = __extbuf_min_; 888 __ebs_ = sizeof(__extbuf_min_); 889 __owns_eb_ = false; 890 } 891 if (!__always_noconv_) { 892 __ibs_ = max<streamsize>(__n, sizeof(__extbuf_min_)); 893 if (__s && __ibs_ > sizeof(__extbuf_min_)) { 894 __intbuf_ = __s; 895 __owns_ib_ = false; 896 } else { 897 __intbuf_ = new char_type[__ibs_]; 898 __owns_ib_ = true; 899 } 900 } else { 901 __ibs_ = 0; 902 __intbuf_ = nullptr; 903 __owns_ib_ = false; 904 } 905 return this; 906} 907 908template <class _CharT, class _Traits> 909typename basic_filebuf<_CharT, _Traits>::pos_type 910basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode) { 911 if (!__cv_) 912 __throw_bad_cast(); 913 914 int __width = __cv_->encoding(); 915 if (__file_ == nullptr || (__width <= 0 && __off != 0) || sync()) 916 return pos_type(off_type(-1)); 917 // __width > 0 || __off == 0 918 int __whence; 919 switch (__way) { 920 case ios_base::beg: 921 __whence = SEEK_SET; 922 break; 923 case ios_base::cur: 924 __whence = SEEK_CUR; 925 break; 926 case ios_base::end: 927 __whence = SEEK_END; 928 break; 929 default: 930 return pos_type(off_type(-1)); 931 } 932# if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) 933 if (fseek(__file_, __width > 0 ? __width * __off : 0, __whence)) 934 return pos_type(off_type(-1)); 935 pos_type __r = ftell(__file_); 936# else 937 if (::fseeko(__file_, __width > 0 ? __width * __off : 0, __whence)) 938 return pos_type(off_type(-1)); 939 pos_type __r = ftello(__file_); 940# endif 941 __r.state(__st_); 942 return __r; 943} 944 945template <class _CharT, class _Traits> 946typename basic_filebuf<_CharT, _Traits>::pos_type 947basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) { 948 if (__file_ == nullptr || sync()) 949 return pos_type(off_type(-1)); 950# if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) 951 if (fseek(__file_, __sp, SEEK_SET)) 952 return pos_type(off_type(-1)); 953# else 954 if (::fseeko(__file_, __sp, SEEK_SET)) 955 return pos_type(off_type(-1)); 956# endif 957 __st_ = __sp.state(); 958 return __sp; 959} 960 961template <class _CharT, class _Traits> 962int basic_filebuf<_CharT, _Traits>::sync() { 963 if (__file_ == nullptr) 964 return 0; 965 if (!__cv_) 966 __throw_bad_cast(); 967 968 if (__cm_ & ios_base::out) { 969 if (this->pptr() != this->pbase()) 970 if (overflow() == traits_type::eof()) 971 return -1; 972 codecvt_base::result __r; 973 do { 974 char* __extbe; 975 __r = __cv_->unshift(__st_, __extbuf_, __extbuf_ + __ebs_, __extbe); 976 size_t __nmemb = static_cast<size_t>(__extbe - __extbuf_); 977 if (fwrite(__extbuf_, 1, __nmemb, __file_) != __nmemb) 978 return -1; 979 } while (__r == codecvt_base::partial); 980 if (__r == codecvt_base::error) 981 return -1; 982 if (fflush(__file_)) 983 return -1; 984 } else if (__cm_ & ios_base::in) { 985 off_type __c; 986 state_type __state = __st_last_; 987 bool __update_st = false; 988 if (__always_noconv_) 989 __c = this->egptr() - this->gptr(); 990 else { 991 int __width = __cv_->encoding(); 992 __c = __extbufend_ - __extbufnext_; 993 if (__width > 0) 994 __c += __width * (this->egptr() - this->gptr()); 995 else { 996 if (this->gptr() != this->egptr()) { 997 const int __off = __cv_->length(__state, __extbuf_, __extbufnext_, this->gptr() - this->eback()); 998 __c += __extbufnext_ - __extbuf_ - __off; 999 __update_st = true; 1000 } 1001 } 1002 } 1003# if defined(_LIBCPP_HAS_NO_OFF_T_FUNCTIONS) 1004 if (fseek(__file_, -__c, SEEK_CUR)) 1005 return -1; 1006# else 1007 if (::fseeko(__file_, -__c, SEEK_CUR)) 1008 return -1; 1009# endif 1010 if (__update_st) 1011 __st_ = __state; 1012 __extbufnext_ = __extbufend_ = __extbuf_; 1013 this->setg(nullptr, nullptr, nullptr); 1014 __cm_ = 0; 1015 } 1016 return 0; 1017} 1018 1019template <class _CharT, class _Traits> 1020void basic_filebuf<_CharT, _Traits>::imbue(const locale& __loc) { 1021 sync(); 1022 __cv_ = &std::use_facet<codecvt<char_type, char, state_type> >(__loc); 1023 bool __old_anc = __always_noconv_; 1024 __always_noconv_ = __cv_->always_noconv(); 1025 if (__old_anc != __always_noconv_) { 1026 this->setg(nullptr, nullptr, nullptr); 1027 this->setp(nullptr, nullptr); 1028 // invariant, char_type is char, else we couldn't get here 1029 if (__always_noconv_) // need to dump __intbuf_ 1030 { 1031 if (__owns_eb_) 1032 delete[] __extbuf_; 1033 __owns_eb_ = __owns_ib_; 1034 __ebs_ = __ibs_; 1035 __extbuf_ = (char*)__intbuf_; 1036 __ibs_ = 0; 1037 __intbuf_ = nullptr; 1038 __owns_ib_ = false; 1039 } else // need to obtain an __intbuf_. 1040 { // If __extbuf_ is user-supplied, use it, else new __intbuf_ 1041 if (!__owns_eb_ && __extbuf_ != __extbuf_min_) { 1042 __ibs_ = __ebs_; 1043 __intbuf_ = (char_type*)__extbuf_; 1044 __owns_ib_ = false; 1045 __extbuf_ = new char[__ebs_]; 1046 __owns_eb_ = true; 1047 } else { 1048 __ibs_ = __ebs_; 1049 __intbuf_ = new char_type[__ibs_]; 1050 __owns_ib_ = true; 1051 } 1052 } 1053 } 1054} 1055 1056template <class _CharT, class _Traits> 1057bool basic_filebuf<_CharT, _Traits>::__read_mode() { 1058 if (!(__cm_ & ios_base::in)) { 1059 this->setp(nullptr, nullptr); 1060 if (__always_noconv_) 1061 this->setg((char_type*)__extbuf_, (char_type*)__extbuf_ + __ebs_, (char_type*)__extbuf_ + __ebs_); 1062 else 1063 this->setg(__intbuf_, __intbuf_ + __ibs_, __intbuf_ + __ibs_); 1064 __cm_ = ios_base::in; 1065 return true; 1066 } 1067 return false; 1068} 1069 1070template <class _CharT, class _Traits> 1071void basic_filebuf<_CharT, _Traits>::__write_mode() { 1072 if (!(__cm_ & ios_base::out)) { 1073 this->setg(nullptr, nullptr, nullptr); 1074 if (__ebs_ > sizeof(__extbuf_min_)) { 1075 if (__always_noconv_) 1076 this->setp((char_type*)__extbuf_, (char_type*)__extbuf_ + (__ebs_ - 1)); 1077 else 1078 this->setp(__intbuf_, __intbuf_ + (__ibs_ - 1)); 1079 } else 1080 this->setp(nullptr, nullptr); 1081 __cm_ = ios_base::out; 1082 } 1083} 1084 1085// basic_ifstream 1086 1087template <class _CharT, class _Traits> 1088class _LIBCPP_TEMPLATE_VIS basic_ifstream : public basic_istream<_CharT, _Traits> { 1089public: 1090 typedef _CharT char_type; 1091 typedef _Traits traits_type; 1092 typedef typename traits_type::int_type int_type; 1093 typedef typename traits_type::pos_type pos_type; 1094 typedef typename traits_type::off_type off_type; 1095# if _LIBCPP_STD_VER >= 26 1096 using native_handle_type = typename basic_filebuf<_CharT, _Traits>::native_handle_type; 1097# endif 1098 1099 _LIBCPP_HIDE_FROM_ABI basic_ifstream(); 1100 _LIBCPP_HIDE_FROM_ABI explicit basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in); 1101# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 1102 _LIBCPP_HIDE_FROM_ABI explicit basic_ifstream(const wchar_t* __s, ios_base::openmode __mode = ios_base::in); 1103# endif 1104 _LIBCPP_HIDE_FROM_ABI explicit basic_ifstream(const string& __s, ios_base::openmode __mode = ios_base::in); 1105# if _LIBCPP_STD_VER >= 17 1106 template <class _Tp, class = enable_if_t<is_same_v<_Tp, filesystem::path>>> 1107 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY 1108 _LIBCPP_HIDE_FROM_ABI explicit basic_ifstream(const _Tp& __p, ios_base::openmode __mode = ios_base::in) 1109 : basic_ifstream(__p.c_str(), __mode) {} 1110# endif // _LIBCPP_STD_VER >= 17 1111 _LIBCPP_HIDE_FROM_ABI basic_ifstream(basic_ifstream&& __rhs); 1112 _LIBCPP_HIDE_FROM_ABI basic_ifstream& operator=(basic_ifstream&& __rhs); 1113 _LIBCPP_HIDE_FROM_ABI void swap(basic_ifstream& __rhs); 1114 1115 _LIBCPP_HIDE_FROM_ABI basic_filebuf<char_type, traits_type>* rdbuf() const; 1116# if _LIBCPP_STD_VER >= 26 1117 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { return rdbuf()->native_handle(); } 1118# endif 1119 _LIBCPP_HIDE_FROM_ABI bool is_open() const; 1120 void open(const char* __s, ios_base::openmode __mode = ios_base::in); 1121# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 1122 void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in); 1123# endif 1124 void open(const string& __s, ios_base::openmode __mode = ios_base::in); 1125# if _LIBCPP_STD_VER >= 17 1126 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI void 1127 open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in) { 1128 return open(__p.c_str(), __mode); 1129 } 1130# endif // _LIBCPP_STD_VER >= 17 1131 1132 _LIBCPP_HIDE_FROM_ABI void __open(int __fd, ios_base::openmode __mode); 1133 _LIBCPP_HIDE_FROM_ABI void close(); 1134 1135private: 1136 basic_filebuf<char_type, traits_type> __sb_; 1137}; 1138 1139template <class _CharT, class _Traits> 1140inline basic_ifstream<_CharT, _Traits>::basic_ifstream() 1141 : basic_istream<char_type, traits_type>(std::addressof(__sb_)) {} 1142 1143template <class _CharT, class _Traits> 1144inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode) 1145 : basic_istream<char_type, traits_type>(std::addressof(__sb_)) { 1146 if (__sb_.open(__s, __mode | ios_base::in) == nullptr) 1147 this->setstate(ios_base::failbit); 1148} 1149 1150# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 1151template <class _CharT, class _Traits> 1152inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const wchar_t* __s, ios_base::openmode __mode) 1153 : basic_istream<char_type, traits_type>(std::addressof(__sb_)) { 1154 if (__sb_.open(__s, __mode | ios_base::in) == nullptr) 1155 this->setstate(ios_base::failbit); 1156} 1157# endif 1158 1159// extension 1160template <class _CharT, class _Traits> 1161inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::openmode __mode) 1162 : basic_istream<char_type, traits_type>(std::addressof(__sb_)) { 1163 if (__sb_.open(__s, __mode | ios_base::in) == nullptr) 1164 this->setstate(ios_base::failbit); 1165} 1166 1167template <class _CharT, class _Traits> 1168inline basic_ifstream<_CharT, _Traits>::basic_ifstream(basic_ifstream&& __rhs) 1169 : basic_istream<char_type, traits_type>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) { 1170 this->set_rdbuf(std::addressof(__sb_)); 1171} 1172 1173template <class _CharT, class _Traits> 1174inline basic_ifstream<_CharT, _Traits>& basic_ifstream<_CharT, _Traits>::operator=(basic_ifstream&& __rhs) { 1175 basic_istream<char_type, traits_type>::operator=(std::move(__rhs)); 1176 __sb_ = std::move(__rhs.__sb_); 1177 return *this; 1178} 1179 1180template <class _CharT, class _Traits> 1181inline void basic_ifstream<_CharT, _Traits>::swap(basic_ifstream& __rhs) { 1182 basic_istream<char_type, traits_type>::swap(__rhs); 1183 __sb_.swap(__rhs.__sb_); 1184} 1185 1186template <class _CharT, class _Traits> 1187inline _LIBCPP_HIDE_FROM_ABI void swap(basic_ifstream<_CharT, _Traits>& __x, basic_ifstream<_CharT, _Traits>& __y) { 1188 __x.swap(__y); 1189} 1190 1191template <class _CharT, class _Traits> 1192inline basic_filebuf<_CharT, _Traits>* basic_ifstream<_CharT, _Traits>::rdbuf() const { 1193 return const_cast<basic_filebuf<char_type, traits_type>*>(std::addressof(__sb_)); 1194} 1195 1196template <class _CharT, class _Traits> 1197inline bool basic_ifstream<_CharT, _Traits>::is_open() const { 1198 return __sb_.is_open(); 1199} 1200 1201template <class _CharT, class _Traits> 1202void basic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) { 1203 if (__sb_.open(__s, __mode | ios_base::in)) 1204 this->clear(); 1205 else 1206 this->setstate(ios_base::failbit); 1207} 1208 1209# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 1210template <class _CharT, class _Traits> 1211void basic_ifstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) { 1212 if (__sb_.open(__s, __mode | ios_base::in)) 1213 this->clear(); 1214 else 1215 this->setstate(ios_base::failbit); 1216} 1217# endif 1218 1219template <class _CharT, class _Traits> 1220void basic_ifstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) { 1221 if (__sb_.open(__s, __mode | ios_base::in)) 1222 this->clear(); 1223 else 1224 this->setstate(ios_base::failbit); 1225} 1226 1227template <class _CharT, class _Traits> 1228inline void basic_ifstream<_CharT, _Traits>::__open(int __fd, ios_base::openmode __mode) { 1229 if (__sb_.__open(__fd, __mode | ios_base::in)) 1230 this->clear(); 1231 else 1232 this->setstate(ios_base::failbit); 1233} 1234 1235template <class _CharT, class _Traits> 1236inline void basic_ifstream<_CharT, _Traits>::close() { 1237 if (__sb_.close() == 0) 1238 this->setstate(ios_base::failbit); 1239} 1240 1241// basic_ofstream 1242 1243template <class _CharT, class _Traits> 1244class _LIBCPP_TEMPLATE_VIS basic_ofstream : public basic_ostream<_CharT, _Traits> { 1245public: 1246 typedef _CharT char_type; 1247 typedef _Traits traits_type; 1248 typedef typename traits_type::int_type int_type; 1249 typedef typename traits_type::pos_type pos_type; 1250 typedef typename traits_type::off_type off_type; 1251# if _LIBCPP_STD_VER >= 26 1252 using native_handle_type = typename basic_filebuf<_CharT, _Traits>::native_handle_type; 1253# endif 1254 1255 _LIBCPP_HIDE_FROM_ABI basic_ofstream(); 1256 _LIBCPP_HIDE_FROM_ABI explicit basic_ofstream(const char* __s, ios_base::openmode __mode = ios_base::out); 1257# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 1258 _LIBCPP_HIDE_FROM_ABI explicit basic_ofstream(const wchar_t* __s, ios_base::openmode __mode = ios_base::out); 1259# endif 1260 _LIBCPP_HIDE_FROM_ABI explicit basic_ofstream(const string& __s, ios_base::openmode __mode = ios_base::out); 1261 1262# if _LIBCPP_STD_VER >= 17 1263 template <class _Tp, class = enable_if_t<is_same_v<_Tp, filesystem::path>>> 1264 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY 1265 _LIBCPP_HIDE_FROM_ABI explicit basic_ofstream(const _Tp& __p, ios_base::openmode __mode = ios_base::out) 1266 : basic_ofstream(__p.c_str(), __mode) {} 1267# endif // _LIBCPP_STD_VER >= 17 1268 1269 _LIBCPP_HIDE_FROM_ABI basic_ofstream(basic_ofstream&& __rhs); 1270 _LIBCPP_HIDE_FROM_ABI basic_ofstream& operator=(basic_ofstream&& __rhs); 1271 _LIBCPP_HIDE_FROM_ABI void swap(basic_ofstream& __rhs); 1272 1273 _LIBCPP_HIDE_FROM_ABI basic_filebuf<char_type, traits_type>* rdbuf() const; 1274# if _LIBCPP_STD_VER >= 26 1275 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { return rdbuf()->native_handle(); } 1276# endif 1277 _LIBCPP_HIDE_FROM_ABI bool is_open() const; 1278 void open(const char* __s, ios_base::openmode __mode = ios_base::out); 1279# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 1280 void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::out); 1281# endif 1282 void open(const string& __s, ios_base::openmode __mode = ios_base::out); 1283 1284# if _LIBCPP_STD_VER >= 17 1285 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI void 1286 open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::out) { 1287 return open(__p.c_str(), __mode); 1288 } 1289# endif // _LIBCPP_STD_VER >= 17 1290 1291 _LIBCPP_HIDE_FROM_ABI void __open(int __fd, ios_base::openmode __mode); 1292 _LIBCPP_HIDE_FROM_ABI void close(); 1293 1294private: 1295 basic_filebuf<char_type, traits_type> __sb_; 1296}; 1297 1298template <class _CharT, class _Traits> 1299inline basic_ofstream<_CharT, _Traits>::basic_ofstream() 1300 : basic_ostream<char_type, traits_type>(std::addressof(__sb_)) {} 1301 1302template <class _CharT, class _Traits> 1303inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode) 1304 : basic_ostream<char_type, traits_type>(std::addressof(__sb_)) { 1305 if (__sb_.open(__s, __mode | ios_base::out) == nullptr) 1306 this->setstate(ios_base::failbit); 1307} 1308 1309# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 1310template <class _CharT, class _Traits> 1311inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const wchar_t* __s, ios_base::openmode __mode) 1312 : basic_ostream<char_type, traits_type>(std::addressof(__sb_)) { 1313 if (__sb_.open(__s, __mode | ios_base::out) == nullptr) 1314 this->setstate(ios_base::failbit); 1315} 1316# endif 1317 1318// extension 1319template <class _CharT, class _Traits> 1320inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::openmode __mode) 1321 : basic_ostream<char_type, traits_type>(std::addressof(__sb_)) { 1322 if (__sb_.open(__s, __mode | ios_base::out) == nullptr) 1323 this->setstate(ios_base::failbit); 1324} 1325 1326template <class _CharT, class _Traits> 1327inline basic_ofstream<_CharT, _Traits>::basic_ofstream(basic_ofstream&& __rhs) 1328 : basic_ostream<char_type, traits_type>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) { 1329 this->set_rdbuf(std::addressof(__sb_)); 1330} 1331 1332template <class _CharT, class _Traits> 1333inline basic_ofstream<_CharT, _Traits>& basic_ofstream<_CharT, _Traits>::operator=(basic_ofstream&& __rhs) { 1334 basic_ostream<char_type, traits_type>::operator=(std::move(__rhs)); 1335 __sb_ = std::move(__rhs.__sb_); 1336 return *this; 1337} 1338 1339template <class _CharT, class _Traits> 1340inline void basic_ofstream<_CharT, _Traits>::swap(basic_ofstream& __rhs) { 1341 basic_ostream<char_type, traits_type>::swap(__rhs); 1342 __sb_.swap(__rhs.__sb_); 1343} 1344 1345template <class _CharT, class _Traits> 1346inline _LIBCPP_HIDE_FROM_ABI void swap(basic_ofstream<_CharT, _Traits>& __x, basic_ofstream<_CharT, _Traits>& __y) { 1347 __x.swap(__y); 1348} 1349 1350template <class _CharT, class _Traits> 1351inline basic_filebuf<_CharT, _Traits>* basic_ofstream<_CharT, _Traits>::rdbuf() const { 1352 return const_cast<basic_filebuf<char_type, traits_type>*>(std::addressof(__sb_)); 1353} 1354 1355template <class _CharT, class _Traits> 1356inline bool basic_ofstream<_CharT, _Traits>::is_open() const { 1357 return __sb_.is_open(); 1358} 1359 1360template <class _CharT, class _Traits> 1361void basic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) { 1362 if (__sb_.open(__s, __mode | ios_base::out)) 1363 this->clear(); 1364 else 1365 this->setstate(ios_base::failbit); 1366} 1367 1368# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 1369template <class _CharT, class _Traits> 1370void basic_ofstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) { 1371 if (__sb_.open(__s, __mode | ios_base::out)) 1372 this->clear(); 1373 else 1374 this->setstate(ios_base::failbit); 1375} 1376# endif 1377 1378template <class _CharT, class _Traits> 1379void basic_ofstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) { 1380 if (__sb_.open(__s, __mode | ios_base::out)) 1381 this->clear(); 1382 else 1383 this->setstate(ios_base::failbit); 1384} 1385 1386template <class _CharT, class _Traits> 1387inline void basic_ofstream<_CharT, _Traits>::__open(int __fd, ios_base::openmode __mode) { 1388 if (__sb_.__open(__fd, __mode | ios_base::out)) 1389 this->clear(); 1390 else 1391 this->setstate(ios_base::failbit); 1392} 1393 1394template <class _CharT, class _Traits> 1395inline void basic_ofstream<_CharT, _Traits>::close() { 1396 if (__sb_.close() == nullptr) 1397 this->setstate(ios_base::failbit); 1398} 1399 1400// basic_fstream 1401 1402template <class _CharT, class _Traits> 1403class _LIBCPP_TEMPLATE_VIS basic_fstream : public basic_iostream<_CharT, _Traits> { 1404public: 1405 typedef _CharT char_type; 1406 typedef _Traits traits_type; 1407 typedef typename traits_type::int_type int_type; 1408 typedef typename traits_type::pos_type pos_type; 1409 typedef typename traits_type::off_type off_type; 1410# if _LIBCPP_STD_VER >= 26 1411 using native_handle_type = typename basic_filebuf<_CharT, _Traits>::native_handle_type; 1412# endif 1413 1414 _LIBCPP_HIDE_FROM_ABI basic_fstream(); 1415 _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(const char* __s, 1416 ios_base::openmode __mode = ios_base::in | ios_base::out); 1417# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 1418 _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(const wchar_t* __s, 1419 ios_base::openmode __mode = ios_base::in | ios_base::out); 1420# endif 1421 _LIBCPP_HIDE_FROM_ABI explicit basic_fstream(const string& __s, 1422 ios_base::openmode __mode = ios_base::in | ios_base::out); 1423 1424# if _LIBCPP_STD_VER >= 17 1425 template <class _Tp, class = enable_if_t<is_same_v<_Tp, filesystem::path>>> 1426 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI explicit basic_fstream( 1427 const _Tp& __p, ios_base::openmode __mode = ios_base::in | ios_base::out) 1428 : basic_fstream(__p.c_str(), __mode) {} 1429# endif // _LIBCPP_STD_VER >= 17 1430 1431 _LIBCPP_HIDE_FROM_ABI basic_fstream(basic_fstream&& __rhs); 1432 1433 _LIBCPP_HIDE_FROM_ABI basic_fstream& operator=(basic_fstream&& __rhs); 1434 1435 _LIBCPP_HIDE_FROM_ABI void swap(basic_fstream& __rhs); 1436 1437 _LIBCPP_HIDE_FROM_ABI basic_filebuf<char_type, traits_type>* rdbuf() const; 1438# if _LIBCPP_STD_VER >= 26 1439 _LIBCPP_HIDE_FROM_ABI native_handle_type native_handle() const noexcept { return rdbuf()->native_handle(); } 1440# endif 1441 _LIBCPP_HIDE_FROM_ABI bool is_open() const; 1442 _LIBCPP_HIDE_FROM_ABI void open(const char* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); 1443# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 1444 void open(const wchar_t* __s, ios_base::openmode __mode = ios_base::in | ios_base::out); 1445# endif 1446 _LIBCPP_HIDE_FROM_ABI void open(const string& __s, ios_base::openmode __mode = ios_base::in | ios_base::out); 1447 1448# if _LIBCPP_STD_VER >= 17 1449 _LIBCPP_AVAILABILITY_FILESYSTEM_LIBRARY _LIBCPP_HIDE_FROM_ABI void 1450 open(const filesystem::path& __p, ios_base::openmode __mode = ios_base::in | ios_base::out) { 1451 return open(__p.c_str(), __mode); 1452 } 1453# endif // _LIBCPP_STD_VER >= 17 1454 1455 _LIBCPP_HIDE_FROM_ABI void close(); 1456 1457private: 1458 basic_filebuf<char_type, traits_type> __sb_; 1459}; 1460 1461template <class _CharT, class _Traits> 1462inline basic_fstream<_CharT, _Traits>::basic_fstream() 1463 : basic_iostream<char_type, traits_type>(std::addressof(__sb_)) {} 1464 1465template <class _CharT, class _Traits> 1466inline basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode) 1467 : basic_iostream<char_type, traits_type>(std::addressof(__sb_)) { 1468 if (__sb_.open(__s, __mode) == nullptr) 1469 this->setstate(ios_base::failbit); 1470} 1471 1472# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 1473template <class _CharT, class _Traits> 1474inline basic_fstream<_CharT, _Traits>::basic_fstream(const wchar_t* __s, ios_base::openmode __mode) 1475 : basic_iostream<char_type, traits_type>(std::addressof(__sb_)) { 1476 if (__sb_.open(__s, __mode) == nullptr) 1477 this->setstate(ios_base::failbit); 1478} 1479# endif 1480 1481template <class _CharT, class _Traits> 1482inline basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openmode __mode) 1483 : basic_iostream<char_type, traits_type>(std::addressof(__sb_)) { 1484 if (__sb_.open(__s, __mode) == nullptr) 1485 this->setstate(ios_base::failbit); 1486} 1487 1488// extension 1489template <class _CharT, class _Traits> 1490inline basic_fstream<_CharT, _Traits>::basic_fstream(basic_fstream&& __rhs) 1491 : basic_iostream<char_type, traits_type>(std::move(__rhs)), __sb_(std::move(__rhs.__sb_)) { 1492 this->set_rdbuf(std::addressof(__sb_)); 1493} 1494 1495template <class _CharT, class _Traits> 1496inline basic_fstream<_CharT, _Traits>& basic_fstream<_CharT, _Traits>::operator=(basic_fstream&& __rhs) { 1497 basic_iostream<char_type, traits_type>::operator=(std::move(__rhs)); 1498 __sb_ = std::move(__rhs.__sb_); 1499 return *this; 1500} 1501 1502template <class _CharT, class _Traits> 1503inline void basic_fstream<_CharT, _Traits>::swap(basic_fstream& __rhs) { 1504 basic_iostream<char_type, traits_type>::swap(__rhs); 1505 __sb_.swap(__rhs.__sb_); 1506} 1507 1508template <class _CharT, class _Traits> 1509inline _LIBCPP_HIDE_FROM_ABI void swap(basic_fstream<_CharT, _Traits>& __x, basic_fstream<_CharT, _Traits>& __y) { 1510 __x.swap(__y); 1511} 1512 1513template <class _CharT, class _Traits> 1514inline basic_filebuf<_CharT, _Traits>* basic_fstream<_CharT, _Traits>::rdbuf() const { 1515 return const_cast<basic_filebuf<char_type, traits_type>*>(std::addressof(__sb_)); 1516} 1517 1518template <class _CharT, class _Traits> 1519inline bool basic_fstream<_CharT, _Traits>::is_open() const { 1520 return __sb_.is_open(); 1521} 1522 1523template <class _CharT, class _Traits> 1524void basic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) { 1525 if (__sb_.open(__s, __mode)) 1526 this->clear(); 1527 else 1528 this->setstate(ios_base::failbit); 1529} 1530 1531# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR 1532template <class _CharT, class _Traits> 1533void basic_fstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) { 1534 if (__sb_.open(__s, __mode)) 1535 this->clear(); 1536 else 1537 this->setstate(ios_base::failbit); 1538} 1539# endif 1540 1541template <class _CharT, class _Traits> 1542void basic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) { 1543 if (__sb_.open(__s, __mode)) 1544 this->clear(); 1545 else 1546 this->setstate(ios_base::failbit); 1547} 1548 1549template <class _CharT, class _Traits> 1550inline void basic_fstream<_CharT, _Traits>::close() { 1551 if (__sb_.close() == nullptr) 1552 this->setstate(ios_base::failbit); 1553} 1554 1555# if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1 1556extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ifstream<char>; 1557extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ofstream<char>; 1558extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_filebuf<char>; 1559# endif 1560 1561_LIBCPP_END_NAMESPACE_STD 1562 1563#endif // _LIBCPP_HAS_NO_FILESYSTEM 1564 1565_LIBCPP_POP_MACROS 1566 1567#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20 1568# include <atomic> 1569# include <concepts> 1570# include <cstdlib> 1571# include <iosfwd> 1572# include <limits> 1573# include <mutex> 1574# include <new> 1575# include <stdexcept> 1576# include <type_traits> 1577#endif 1578 1579#endif // _LIBCPP_FSTREAM 1580