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