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