#ifndef _LIBCPP_FSTREAM
#define _LIBCPP_FSTREAM
#include <__algorithm/max.h>
#include <__assert>
#include <__config>
#include <__fwd/fstream.h>
#include <__locale>
#include <__memory/addressof.h>
#include <__type_traits/enable_if.h>
#include <__type_traits/is_same.h>
#include <__utility/move.h>
#include <__utility/swap.h>
#include <__utility/unreachable.h>
#include <cstdio>
#include <filesystem>
#include <istream>
#include <ostream>
#include <typeinfo>
#include <version>
#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER)
# pragma GCC system_header
#endif
_LIBCPP_PUSH_MACROS
#include <__undef_macros>
#if defined(_LIBCPP_MSVCRT) || defined(_NEWLIB_VERSION)
#define _LIBCPP_HAS_NO_OFF_T_FUNCTIONS
#endif
#if !defined(_LIBCPP_HAS_NO_FILESYSTEM)
_LIBCPP_BEGIN_NAMESPACE_STD
# if _LIBCPP_STD_VER >= 26 && defined(_LIBCPP_WIN32API)
_LIBCPP_EXPORTED_FROM_ABI void* __filebuf_windows_native_handle(FILE* __file) noexcept;
# endif
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_filebuf : public basic_streambuf<_CharT, _Traits> { … };
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>::basic_filebuf()
: … { … }
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>::basic_filebuf(basic_filebuf&& __rhs) : … { … }
template <class _CharT, class _Traits>
inline basic_filebuf<_CharT, _Traits>& basic_filebuf<_CharT, _Traits>::operator=(basic_filebuf&& __rhs) { … }
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>::~basic_filebuf() { … }
template <class _CharT, class _Traits>
void basic_filebuf<_CharT, _Traits>::swap(basic_filebuf& __rhs) { … }
template <class _CharT, class _Traits>
inline _LIBCPP_HIDE_FROM_ABI void swap(basic_filebuf<_CharT, _Traits>& __x, basic_filebuf<_CharT, _Traits>& __y) { … }
template <class _CharT, class _Traits>
inline bool basic_filebuf<_CharT, _Traits>::is_open() const { … }
template <class _CharT, class _Traits>
const char* basic_filebuf<_CharT, _Traits>::__make_mdstring(ios_base::openmode __mode) _NOEXCEPT { … }
# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
const wchar_t* basic_filebuf<_CharT, _Traits>::__make_mdwstring(ios_base::openmode __mode) _NOEXCEPT {
switch (__mode & ~ios_base::ate) {
case ios_base::out:
case ios_base::out | ios_base::trunc:
return L"w";
case ios_base::out | ios_base::app:
case ios_base::app:
return L"a";
case ios_base::in:
return L"r";
case ios_base::in | ios_base::out:
return L"r+";
case ios_base::in | ios_base::out | ios_base::trunc:
return L"w+";
case ios_base::in | ios_base::out | ios_base::app:
case ios_base::in | ios_base::app:
return L"a+";
case ios_base::out | ios_base::binary:
case ios_base::out | ios_base::trunc | ios_base::binary:
return L"wb";
case ios_base::out | ios_base::app | ios_base::binary:
case ios_base::app | ios_base::binary:
return L"ab";
case ios_base::in | ios_base::binary:
return L"rb";
case ios_base::in | ios_base::out | ios_base::binary:
return L"r+b";
case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary:
return L"w+b";
case ios_base::in | ios_base::out | ios_base::app | ios_base::binary:
case ios_base::in | ios_base::app | ios_base::binary:
return L"a+b";
# if _LIBCPP_STD_VER >= 23
case ios_base::out | ios_base::noreplace:
case ios_base::out | ios_base::trunc | ios_base::noreplace:
return L"wx";
case ios_base::in | ios_base::out | ios_base::trunc | ios_base::noreplace:
return L"w+x";
case ios_base::out | ios_base::binary | ios_base::noreplace:
case ios_base::out | ios_base::trunc | ios_base::binary | ios_base::noreplace:
return L"wbx";
case ios_base::in | ios_base::out | ios_base::trunc | ios_base::binary | ios_base::noreplace:
return L"w+bx";
# endif
default:
return nullptr;
}
__libcpp_unreachable();
}
# endif
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) { … }
template <class _CharT, class _Traits>
inline basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::__open(int __fd, ios_base::openmode __mode) { … }
# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) {
if (__file_)
return nullptr;
const wchar_t* __mdstr = __make_mdwstring(__mode);
if (!__mdstr)
return nullptr;
return __do_open(_wfopen(__s, __mdstr), __mode);
}
# endif
template <class _CharT, class _Traits>
inline basic_filebuf<_CharT, _Traits>*
basic_filebuf<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) { … }
template <class _CharT, class _Traits>
basic_filebuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::close() { … }
template <class _CharT, class _Traits>
typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::underflow() { … }
template <class _CharT, class _Traits>
typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::pbackfail(int_type __c) { … }
template <class _CharT, class _Traits>
typename basic_filebuf<_CharT, _Traits>::int_type basic_filebuf<_CharT, _Traits>::overflow(int_type __c) { … }
template <class _CharT, class _Traits>
basic_streambuf<_CharT, _Traits>* basic_filebuf<_CharT, _Traits>::setbuf(char_type* __s, streamsize __n) { … }
template <class _CharT, class _Traits>
typename basic_filebuf<_CharT, _Traits>::pos_type
basic_filebuf<_CharT, _Traits>::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode) { … }
template <class _CharT, class _Traits>
typename basic_filebuf<_CharT, _Traits>::pos_type
basic_filebuf<_CharT, _Traits>::seekpos(pos_type __sp, ios_base::openmode) { … }
template <class _CharT, class _Traits>
int basic_filebuf<_CharT, _Traits>::sync() { … }
template <class _CharT, class _Traits>
void basic_filebuf<_CharT, _Traits>::imbue(const locale& __loc) { … }
template <class _CharT, class _Traits>
bool basic_filebuf<_CharT, _Traits>::__read_mode() { … }
template <class _CharT, class _Traits>
void basic_filebuf<_CharT, _Traits>::__write_mode() { … }
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_ifstream : public basic_istream<_CharT, _Traits> { … };
template <class _CharT, class _Traits>
inline basic_ifstream<_CharT, _Traits>::basic_ifstream()
: … { … }
template <class _CharT, class _Traits>
inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const char* __s, ios_base::openmode __mode)
: … { … }
# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const wchar_t* __s, ios_base::openmode __mode)
: basic_istream<char_type, traits_type>(std::addressof(__sb_)) {
if (__sb_.open(__s, __mode | ios_base::in) == nullptr)
this->setstate(ios_base::failbit);
}
# endif
template <class _CharT, class _Traits>
inline basic_ifstream<_CharT, _Traits>::basic_ifstream(const string& __s, ios_base::openmode __mode)
: … { … }
template <class _CharT, class _Traits>
inline basic_ifstream<_CharT, _Traits>::basic_ifstream(basic_ifstream&& __rhs)
: … { … }
template <class _CharT, class _Traits>
inline basic_ifstream<_CharT, _Traits>& basic_ifstream<_CharT, _Traits>::operator=(basic_ifstream&& __rhs) { … }
template <class _CharT, class _Traits>
inline void basic_ifstream<_CharT, _Traits>::swap(basic_ifstream& __rhs) { … }
template <class _CharT, class _Traits>
inline _LIBCPP_HIDE_FROM_ABI void swap(basic_ifstream<_CharT, _Traits>& __x, basic_ifstream<_CharT, _Traits>& __y) { … }
template <class _CharT, class _Traits>
inline basic_filebuf<_CharT, _Traits>* basic_ifstream<_CharT, _Traits>::rdbuf() const { … }
template <class _CharT, class _Traits>
inline bool basic_ifstream<_CharT, _Traits>::is_open() const { … }
template <class _CharT, class _Traits>
void basic_ifstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) { … }
# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
void basic_ifstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) {
if (__sb_.open(__s, __mode | ios_base::in))
this->clear();
else
this->setstate(ios_base::failbit);
}
# endif
template <class _CharT, class _Traits>
void basic_ifstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) { … }
template <class _CharT, class _Traits>
inline void basic_ifstream<_CharT, _Traits>::__open(int __fd, ios_base::openmode __mode) { … }
template <class _CharT, class _Traits>
inline void basic_ifstream<_CharT, _Traits>::close() { … }
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_ofstream : public basic_ostream<_CharT, _Traits> { … };
template <class _CharT, class _Traits>
inline basic_ofstream<_CharT, _Traits>::basic_ofstream()
: … { … }
template <class _CharT, class _Traits>
inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const char* __s, ios_base::openmode __mode)
: … { … }
# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const wchar_t* __s, ios_base::openmode __mode)
: basic_ostream<char_type, traits_type>(std::addressof(__sb_)) {
if (__sb_.open(__s, __mode | ios_base::out) == nullptr)
this->setstate(ios_base::failbit);
}
# endif
template <class _CharT, class _Traits>
inline basic_ofstream<_CharT, _Traits>::basic_ofstream(const string& __s, ios_base::openmode __mode)
: … { … }
template <class _CharT, class _Traits>
inline basic_ofstream<_CharT, _Traits>::basic_ofstream(basic_ofstream&& __rhs)
: … { … }
template <class _CharT, class _Traits>
inline basic_ofstream<_CharT, _Traits>& basic_ofstream<_CharT, _Traits>::operator=(basic_ofstream&& __rhs) { … }
template <class _CharT, class _Traits>
inline void basic_ofstream<_CharT, _Traits>::swap(basic_ofstream& __rhs) { … }
template <class _CharT, class _Traits>
inline _LIBCPP_HIDE_FROM_ABI void swap(basic_ofstream<_CharT, _Traits>& __x, basic_ofstream<_CharT, _Traits>& __y) { … }
template <class _CharT, class _Traits>
inline basic_filebuf<_CharT, _Traits>* basic_ofstream<_CharT, _Traits>::rdbuf() const { … }
template <class _CharT, class _Traits>
inline bool basic_ofstream<_CharT, _Traits>::is_open() const { … }
template <class _CharT, class _Traits>
void basic_ofstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) { … }
# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
void basic_ofstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) {
if (__sb_.open(__s, __mode | ios_base::out))
this->clear();
else
this->setstate(ios_base::failbit);
}
# endif
template <class _CharT, class _Traits>
void basic_ofstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) { … }
template <class _CharT, class _Traits>
inline void basic_ofstream<_CharT, _Traits>::__open(int __fd, ios_base::openmode __mode) { … }
template <class _CharT, class _Traits>
inline void basic_ofstream<_CharT, _Traits>::close() { … }
template <class _CharT, class _Traits>
class _LIBCPP_TEMPLATE_VIS basic_fstream : public basic_iostream<_CharT, _Traits> { … };
template <class _CharT, class _Traits>
inline basic_fstream<_CharT, _Traits>::basic_fstream()
: … { … }
template <class _CharT, class _Traits>
inline basic_fstream<_CharT, _Traits>::basic_fstream(const char* __s, ios_base::openmode __mode)
: … { … }
# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
inline basic_fstream<_CharT, _Traits>::basic_fstream(const wchar_t* __s, ios_base::openmode __mode)
: basic_iostream<char_type, traits_type>(std::addressof(__sb_)) {
if (__sb_.open(__s, __mode) == nullptr)
this->setstate(ios_base::failbit);
}
# endif
template <class _CharT, class _Traits>
inline basic_fstream<_CharT, _Traits>::basic_fstream(const string& __s, ios_base::openmode __mode)
: … { … }
template <class _CharT, class _Traits>
inline basic_fstream<_CharT, _Traits>::basic_fstream(basic_fstream&& __rhs)
: … { … }
template <class _CharT, class _Traits>
inline basic_fstream<_CharT, _Traits>& basic_fstream<_CharT, _Traits>::operator=(basic_fstream&& __rhs) { … }
template <class _CharT, class _Traits>
inline void basic_fstream<_CharT, _Traits>::swap(basic_fstream& __rhs) { … }
template <class _CharT, class _Traits>
inline _LIBCPP_HIDE_FROM_ABI void swap(basic_fstream<_CharT, _Traits>& __x, basic_fstream<_CharT, _Traits>& __y) { … }
template <class _CharT, class _Traits>
inline basic_filebuf<_CharT, _Traits>* basic_fstream<_CharT, _Traits>::rdbuf() const { … }
template <class _CharT, class _Traits>
inline bool basic_fstream<_CharT, _Traits>::is_open() const { … }
template <class _CharT, class _Traits>
void basic_fstream<_CharT, _Traits>::open(const char* __s, ios_base::openmode __mode) { … }
# ifdef _LIBCPP_HAS_OPEN_WITH_WCHAR
template <class _CharT, class _Traits>
void basic_fstream<_CharT, _Traits>::open(const wchar_t* __s, ios_base::openmode __mode) {
if (__sb_.open(__s, __mode))
this->clear();
else
this->setstate(ios_base::failbit);
}
# endif
template <class _CharT, class _Traits>
void basic_fstream<_CharT, _Traits>::open(const string& __s, ios_base::openmode __mode) { … }
template <class _CharT, class _Traits>
inline void basic_fstream<_CharT, _Traits>::close() { … }
# if _LIBCPP_AVAILABILITY_HAS_ADDITIONAL_IOSTREAM_EXPLICIT_INSTANTIATIONS_1
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ifstream<char>;
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_ofstream<char>;
extern template class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_filebuf<char>;
# endif
_LIBCPP_END_NAMESPACE_STD
#endif
_LIBCPP_POP_MACROS
#if !defined(_LIBCPP_REMOVE_TRANSITIVE_INCLUDES) && _LIBCPP_STD_VER <= 20
# include <atomic>
# include <concepts>
# include <cstdlib>
# include <iosfwd>
# include <limits>
# include <mutex>
# include <new>
# include <stdexcept>
# include <type_traits>
#endif
#endif