685a38dd94439ce0589c71c1faabfb633d3f7293
[platform/upstream/gcc.git] / libstdc++-v3 / include / std / std_fstream.h
1 // File based streams -*- C++ -*-
2
3 // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002
4 // Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library.  This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
10 // any later version.
11
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING.  If not, write to the Free
19 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
20 // USA.
21
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction.  Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License.  This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
30
31 //
32 // ISO C++ 14882: 27.8  File-based streams
33 //
34
35 /** @file fstream
36  *  This is a Standard C++ Library header.  You should @c #include this header
37  *  in your programs, rather than any of the "st[dl]_*.h" implementation files.
38  */
39
40 #ifndef _CPP_FSTREAM
41 #define _CPP_FSTREAM    1
42
43 #pragma GCC system_header
44
45 #include <istream>
46 #include <ostream>
47 #include <locale>       // For codecvt
48 #include <bits/basic_file.h>
49 #include <bits/gthr.h>
50
51 namespace std
52 {
53   // [27.8.1.1] template class basic_filebuf
54   /**
55    *  @brief  The actual work of input and output (for files).
56    *
57    *  This class associates both its input and output sequence with an
58    *  external disk file, and maintains a joint file position for both
59    *  sequences.  Many of its sematics are described in terms of similar
60    *  behavior in the Standard C Library's @c FILE streams.
61   */
62   template<typename _CharT, typename _Traits>
63     class basic_filebuf : public basic_streambuf<_CharT, _Traits>
64     {
65     public:
66       // Types:
67       typedef _CharT                                    char_type;
68       typedef _Traits                                   traits_type;
69       typedef typename traits_type::int_type            int_type;
70       typedef typename traits_type::pos_type            pos_type;
71       typedef typename traits_type::off_type            off_type;
72
73       //@{
74       /**
75        *  @if maint
76        *  @doctodo
77        *  @endif
78       */
79       typedef basic_streambuf<char_type, traits_type>   __streambuf_type;
80       typedef basic_filebuf<char_type, traits_type>     __filebuf_type;
81       typedef __basic_file<char>                        __file_type;
82       typedef typename traits_type::state_type          __state_type;
83       typedef codecvt<char_type, char, __state_type>    __codecvt_type;
84       typedef typename __codecvt_type::result           __res_type;
85       typedef ctype<char_type>                          __ctype_type;
86       //@}
87
88       friend class ios_base; // For sync_with_stdio.
89
90     protected:
91       // Data Members:
92       // MT lock inherited from libio or other low-level io library.
93       /**
94        *  @if maint
95        *  @doctodo
96        *  @endif
97       */
98       __c_lock                  _M_lock;
99
100       // External buffer.
101       /**
102        *  @if maint
103        *  @doctodo
104        *  @endif
105       */
106       __file_type               _M_file;
107
108       // Current and beginning state type for codecvt.
109       /**
110        *  @if maint
111        *  @doctodo
112        *  @endif
113       */
114       __state_type              _M_state_cur;
115       __state_type              _M_state_beg;
116
117       // Set iff _M_buf is allocated memory from _M_allocate_internal_buffer.
118       /**
119        *  @if maint
120        *  @doctodo
121        *  @endif
122       */
123       bool                      _M_buf_allocated;
124       
125       // XXX Needed?
126       bool                      _M_last_overflowed;
127
128       // The position in the buffer corresponding to the external file
129       // pointer.
130       /**
131        *  @if maint
132        *  @doctodo
133        *  @endif
134       */
135       char_type*                _M_filepos;
136
137     public:
138       // Constructors/destructor:
139       /**
140        *  @brief  Does not open any files.
141        *
142        *  The default constructor initializes the parent class using its
143        *  own default ctor.
144       */
145       basic_filebuf();
146
147       /**
148        *  @brief  The destructor closes the file first.
149       */
150       virtual
151       ~basic_filebuf()
152       {
153         this->close();
154         _M_last_overflowed = false;
155       }
156
157       // Members:
158       /**
159        *  @brief  Returns true if the external file is open.
160       */
161       bool
162       is_open() const { return _M_file.is_open(); }
163
164       /**
165        *  @brief  Opens an external file.
166        *  @param  s  The name of the file.
167        *  @param  mode  The open mode flags.
168        *  @return  @c this on success, NULL on failure
169        *
170        *  If a file is already open, this function immediately fails.
171        *  Otherwise it tries to open the file named @a s using the flags
172        *  given in @a mode.
173        *
174        *  [Table 92 gives the relation between openmode combinations and the
175        *  equivalent fopen() flags, but the table has not been copied yet.]
176       */
177       __filebuf_type*
178       open(const char* __s, ios_base::openmode __mode);
179
180       /**
181        *  @brief  Closes the currently associated file.
182        *  @return  @c this on success, NULL on failure
183        *
184        *  If no file is currently open, this function immediately fails.
185        *
186        *  If a "put buffer area" exists, @c overflow(eof) is called to flush
187        *  all the characters.  The file is then closed.
188        *
189        *  If any operations fail, this function also fails.
190       */
191       __filebuf_type*
192       close();
193
194     protected:
195       /**
196        *  @if maint
197        *  @doctodo
198        *  @endif
199       */
200       void
201       _M_allocate_internal_buffer();
202
203       /**
204        *  @if maint
205        *  @doctodo
206        *  @endif
207       */
208       void
209       _M_destroy_internal_buffer();
210
211       // [27.8.1.4] overridden virtual functions
212       // [documentation is inherited]
213       virtual streamsize
214       showmanyc();
215
216       // Stroustrup, 1998, p. 628
217       // underflow() and uflow() functions are called to get the next
218       // charater from the real input source when the buffer is empty.
219       // Buffered input uses underflow()
220
221       // The only difference between underflow() and uflow() is that the
222       // latter bumps _M_in_cur after the read.  In the sync_with_stdio
223       // case, this is important, as we need to unget the read character in
224       // the underflow() case in order to maintain synchronization.  So
225       // instead of calling underflow() from uflow(), we create a common
226       // subroutine to do the real work.
227       /**
228        *  @if maint
229        *  @doctodo
230        *  @endif
231       */
232       int_type
233       _M_underflow_common(bool __bump);
234
235       // [documentation is inherited]
236       virtual int_type
237       underflow() { return _M_underflow_common(false); }
238
239       // [documentation is inherited]
240       virtual int_type
241       uflow() { return _M_underflow_common(true); }
242
243       // [documentation is inherited]
244       virtual int_type
245       pbackfail(int_type __c = _Traits::eof());
246
247       // NB: For what the standard expects of the overflow function,
248       // see _M_really_overflow(), below. Because basic_streambuf's
249       // sputc/sputn call overflow directly, and the complications of
250       // this implementation's setting of the initial pointers all
251       // equal to _M_buf when initializing, it seems essential to have
252       // this in actuality be a helper function that checks for the
253       // eccentricities of this implementation, and then call
254       // overflow() if indeed the buffer is full.
255
256       // [documentation is inherited]
257       virtual int_type
258       overflow(int_type __c = _Traits::eof());
259
260       // Stroustrup, 1998, p 648
261       // The overflow() function is called to transfer characters to the
262       // real output destination when the buffer is full. A call to
263       // overflow(c) outputs the contents of the buffer plus the
264       // character c.
265       // 27.5.2.4.5
266       // Consume some sequence of the characters in the pending sequence.
267       /**
268        *  @if maint
269        *  @doctodo
270        *  @endif
271       */
272       int_type
273       _M_really_overflow(int_type __c = _Traits::eof());
274
275       // Convert internal byte sequence to external, char-based
276       // sequence via codecvt.
277       /**
278        *  @if maint
279        *  @doctodo
280        *  @endif
281       */
282       void
283       _M_convert_to_external(char_type*, streamsize, streamsize&, streamsize&);
284
285       /**
286        *  @brief  Manipulates the buffer.
287        *  @param  s  Pointer to a buffer area.
288        *  @param  n  Size of @a s.
289        *  @return  @c this
290        *
291        *  If no file has been opened, and both @a s and @a n are zero, then
292        *  the stream becomes unbuffered.  Otherwise, @c s is used as a
293        *  buffer; see
294        *  http://gcc.gnu.org/onlinedocs/libstdc++/27_io/howto.html#2
295        *  for more.
296       */
297       virtual __streambuf_type*
298       setbuf(char_type* __s, streamsize __n);
299
300       // [documentation is inherited]
301       virtual pos_type
302       seekoff(off_type __off, ios_base::seekdir __way,
303               ios_base::openmode __mode = ios_base::in | ios_base::out);
304
305       // [documentation is inherited]
306       virtual pos_type
307       seekpos(pos_type __pos,
308               ios_base::openmode __mode = ios_base::in | ios_base::out);
309
310       // [documentation is inherited]
311       virtual int
312       sync()
313       {
314         bool __testput = _M_out_cur && _M_out_beg < _M_out_end;
315
316         // Make sure that the internal buffer resyncs its idea of
317         // the file position with the external file.
318         if (__testput)
319           {
320             // Need to restore current position after the write.
321             off_type __off = _M_out_cur - _M_out_end;
322             _M_really_overflow(); // _M_file.sync() will be called within
323             if (__off)
324               _M_file.seekoff(__off, ios_base::cur);
325           }
326         else
327           _M_file.sync();
328         _M_last_overflowed = false;
329         return 0;
330       }
331
332       // [documentation is inherited]
333       virtual void
334       imbue(const locale& __loc);
335
336       // [documentation is inherited]
337       virtual streamsize
338       xsgetn(char_type* __s, streamsize __n)
339       {
340         streamsize __ret = 0;
341         // Clear out pback buffer before going on to the real deal...
342         if (_M_pback_init)
343           {
344             while (__ret < __n && _M_in_cur < _M_in_end)
345               {
346                 *__s = *_M_in_cur;
347                 ++__ret;
348                 ++__s;
349                 ++_M_in_cur;
350               }
351             _M_pback_destroy();
352           }
353         if (__ret < __n)
354           __ret += __streambuf_type::xsgetn(__s, __n - __ret);
355         return __ret;
356       }
357
358       // [documentation is inherited]
359       virtual streamsize
360       xsputn(const char_type* __s, streamsize __n)
361       {
362         _M_pback_destroy();
363         return __streambuf_type::xsputn(__s, __n);
364       }
365
366       /**
367        *  @if maint
368        *  @doctodo
369        *  @endif
370       */
371       void
372       _M_output_unshift();
373
374       // These three functions are used to clarify internal buffer
375       // maintenance. After an overflow, or after a seekoff call that
376       // started at beg or end, or possibly when the stream becomes
377       // unbuffered, and a myrid other obscure corner cases, the
378       // internal buffer does not truly reflect the contents of the
379       // external buffer. At this point, for whatever reason, it is in
380       // an indeterminate state.
381       /**
382        *  @if maint
383        *  @doctodo
384        *  @endif
385       */
386       void
387       _M_set_indeterminate(void)
388       {
389         if (_M_mode & ios_base::in)
390           this->setg(_M_buf, _M_buf, _M_buf);
391         if (_M_mode & ios_base::out)
392           this->setp(_M_buf, _M_buf);
393         _M_filepos = _M_buf;
394       }
395
396       /**
397        *  @if maint
398        *  @doctodo
399        *  @endif
400       */
401       void
402       _M_set_determinate(off_type __off)
403       {
404         bool __testin = _M_mode & ios_base::in;
405         bool __testout = _M_mode & ios_base::out;
406         if (__testin)
407           this->setg(_M_buf, _M_buf, _M_buf + __off);
408         if (__testout)
409           this->setp(_M_buf, _M_buf + __off);
410         _M_filepos = _M_buf + __off;
411       }
412
413       /**
414        *  @if maint
415        *  @doctodo
416        *  @endif
417       */
418       bool
419       _M_is_indeterminate(void)
420       { 
421         bool __ret = false;
422         // Don't return true if unbuffered.
423         if (_M_buf)
424           {
425             if (_M_mode & ios_base::in)
426               __ret = _M_in_beg == _M_in_cur && _M_in_cur == _M_in_end;
427             if (_M_mode & ios_base::out)
428               __ret = _M_out_beg == _M_out_cur && _M_out_cur == _M_out_end;
429           }
430         return __ret;
431       }
432     };
433
434   // Explicit specializations, defined in src/fstream.cc.
435   template<> 
436     basic_filebuf<char>::int_type 
437     basic_filebuf<char>::_M_underflow_common(bool __bump);
438
439  #ifdef _GLIBCPP_USE_WCHAR_T
440   template<> 
441     basic_filebuf<wchar_t>::int_type 
442     basic_filebuf<wchar_t>::_M_underflow_common(bool __bump);
443  #endif
444
445   // [27.8.1.5] Template class basic_ifstream
446   /**
447    *  @brief  Controlling input for files.
448    *
449    *  This class supports reading from named files, using the inherited
450    *  functions from std::basic_istream.  To control the associated
451    *  sequence, an instance of std::basic_filebuf is used, which this page
452    *  refers to as @c sb.
453   */
454   template<typename _CharT, typename _Traits>
455     class basic_ifstream : public basic_istream<_CharT, _Traits>
456     {
457     public:
458       // Types:
459       typedef _CharT                                    char_type;
460       typedef _Traits                                   traits_type;
461       typedef typename traits_type::int_type            int_type;
462       typedef typename traits_type::pos_type            pos_type;
463       typedef typename traits_type::off_type            off_type;
464
465       // Non-standard types:
466       typedef basic_filebuf<char_type, traits_type>     __filebuf_type;
467       typedef basic_istream<char_type, traits_type>     __istream_type;
468
469     private:
470       /**
471        *  @if maint
472        *  @doctodo
473        *  @endif
474       */
475       __filebuf_type    _M_filebuf;
476
477     public:
478       // Constructors/Destructors:
479       /**
480        *  @brief  Default constructor.
481        *
482        *  Initializes @c sb using its default constructor, and passes
483        *  @c &sb to the base class initializer.  Does not open any files
484        *  (you haven't given it a filename to open).
485       */
486       basic_ifstream()
487       : __istream_type(NULL), _M_filebuf()
488       { this->init(&_M_filebuf); }
489
490       /**
491        *  @brief  Create an input file stream.
492        *  @param  s  Null terminated string specifying the filename.
493        *  @param  mode  Open file in specified mode (see std::ios_base).
494        *
495        *  @c ios_base::in is automatically included in @a mode.
496        *
497        *  Tip:  When using std::string to hold the filename, you must use
498        *  .c_str() before passing it to this constructor.
499       */
500       explicit
501       basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)
502       : __istream_type(NULL), _M_filebuf()
503       {
504         this->init(&_M_filebuf);
505         this->open(__s, __mode);
506       }
507
508       /**
509        *  @brief  The destructor does nothing.
510        *
511        *  The file is closed by the filebuf object, not the formatting
512        *  stream.
513       */
514       ~basic_ifstream()
515       { }
516
517       // Members:
518       /**
519        *  @brief  Accessing the underlying buffer.
520        *  @return  The current basic_filebuf buffer.
521        *
522        *  This hides both signatures of std::basic_ios::rdbuf().
523       */
524       __filebuf_type*
525       rdbuf() const
526       { return const_cast<__filebuf_type*>(&_M_filebuf); }
527
528       /**
529        *  @brief  Wrapper to test for an open file.
530        *  @return  @c rdbuf()->is_open()
531       */
532       bool
533       is_open() { return _M_filebuf.is_open(); }
534
535       /**
536        *  @brief  Opens an external file.
537        *  @param  s  The name of the file.
538        *  @param  mode  The open mode flags.
539        *
540        *  Calls @c std::basic_filebuf::open(s,mode|in).  If that function
541        *  fails, @c failbit is set in the stream's error state.
542        *
543        *  Tip:  When using std::string to hold the filename, you must use
544        *  .c_str() before passing it to this constructor.
545       */
546       void
547       open(const char* __s, ios_base::openmode __mode = ios_base::in)
548       {
549         if (!_M_filebuf.open(__s, __mode | ios_base::in))
550           this->setstate(ios_base::failbit);
551       }
552
553       /**
554        *  @brief  Close the file.
555        *
556        *  Calls @c std::basic_filebuf::close().  If that function
557        *  fails, @c failbit is set in the stream's error state.
558       */
559       void
560       close()
561       {
562         if (!_M_filebuf.close())
563           this->setstate(ios_base::failbit);
564       }
565     };
566
567
568   // [27.8.1.8] Template class basic_ofstream
569   /**
570    *  @brief  Controlling output for files.
571    *
572    *  This class supports reading from named files, using the inherited
573    *  functions from std::basic_ostream.  To control the associated
574    *  sequence, an instance of std::basic_filebuf is used, which this page
575    *  refers to as @c sb.
576   */
577   template<typename _CharT, typename _Traits>
578     class basic_ofstream : public basic_ostream<_CharT,_Traits>
579     {
580     public:
581       // Types:
582       typedef _CharT                                    char_type;
583       typedef _Traits                                   traits_type;
584       typedef typename traits_type::int_type            int_type;
585       typedef typename traits_type::pos_type            pos_type;
586       typedef typename traits_type::off_type            off_type;
587
588       // Non-standard types:
589       typedef basic_filebuf<char_type, traits_type>     __filebuf_type;
590       typedef basic_ostream<char_type, traits_type>     __ostream_type;
591
592     private:
593       /**
594        *  @if maint
595        *  @doctodo
596        *  @endif
597       */
598       __filebuf_type    _M_filebuf;
599
600     public:
601       // Constructors:
602       /**
603        *  @brief  Default constructor.
604        *
605        *  Initializes @c sb using its default constructor, and passes
606        *  @c &sb to the base class initializer.  Does not open any files
607        *  (you haven't given it a filename to open).
608       */
609       basic_ofstream()
610       : __ostream_type(NULL), _M_filebuf()
611       { this->init(&_M_filebuf); }
612
613       /**
614        *  @brief  Create an output file stream.
615        *  @param  s  Null terminated string specifying the filename.
616        *  @param  mode  Open file in specified mode (see std::ios_base).
617        *
618        *  @c ios_base::out|ios_base::trunc is automatically included in
619        *  @a mode.
620        *
621        *  Tip:  When using std::string to hold the filename, you must use
622        *  .c_str() before passing it to this constructor.
623       */
624       explicit
625       basic_ofstream(const char* __s,
626                      ios_base::openmode __mode = ios_base::out|ios_base::trunc)
627       : __ostream_type(NULL), _M_filebuf()
628       {
629         this->init(&_M_filebuf);
630         this->open(__s, __mode);
631       }
632
633       /**
634        *  @brief  The destructor does nothing.
635        *
636        *  The file is closed by the filebuf object, not the formatting
637        *  stream.
638       */
639       ~basic_ofstream()
640       { }
641
642       // Members:
643       /**
644        *  @brief  Accessing the underlying buffer.
645        *  @return  The current basic_filebuf buffer.
646        *
647        *  This hides both signatures of std::basic_ios::rdbuf().
648       */
649       __filebuf_type*
650       rdbuf() const
651       { return const_cast<__filebuf_type*>(&_M_filebuf); }
652
653       /**
654        *  @brief  Wrapper to test for an open file.
655        *  @return  @c rdbuf()->is_open()
656       */
657       bool
658       is_open() { return _M_filebuf.is_open(); }
659
660       /**
661        *  @brief  Opens an external file.
662        *  @param  s  The name of the file.
663        *  @param  mode  The open mode flags.
664        *
665        *  Calls @c std::basic_filebuf::open(s,mode|out|trunc).  If that
666        *  function fails, @c failbit is set in the stream's error state.
667        *
668        *  Tip:  When using std::string to hold the filename, you must use
669        *  .c_str() before passing it to this constructor.
670       */
671       void
672       open(const char* __s,
673            ios_base::openmode __mode = ios_base::out | ios_base::trunc)
674       {
675         if (!_M_filebuf.open(__s, __mode | ios_base::out))
676           this->setstate(ios_base::failbit);
677       }
678
679       /**
680        *  @brief  Close the file.
681        *
682        *  Calls @c std::basic_filebuf::close().  If that function
683        *  fails, @c failbit is set in the stream's error state.
684       */
685       void
686       close()
687       {
688         if (!_M_filebuf.close())
689           this->setstate(ios_base::failbit);
690       }
691     };
692
693
694   // [27.8.1.11] Template class basic_fstream
695   /**
696    *  @brief  Controlling intput and output for files.
697    *
698    *  This class supports reading from and writing to named files, using
699    *  the inherited functions from std::basic_iostream.  To control the
700    *  associated sequence, an instance of std::basic_filebuf is used, which
701    *  this page refers to as @c sb.
702   */
703   template<typename _CharT, typename _Traits>
704     class basic_fstream : public basic_iostream<_CharT, _Traits>
705     {
706     public:
707       // Types:
708       typedef _CharT                                    char_type;
709       typedef _Traits                                   traits_type;
710       typedef typename traits_type::int_type            int_type;
711       typedef typename traits_type::pos_type            pos_type;
712       typedef typename traits_type::off_type            off_type;
713
714       // Non-standard types:
715       typedef basic_filebuf<char_type, traits_type>     __filebuf_type;
716       typedef basic_ios<char_type, traits_type>         __ios_type;
717       typedef basic_iostream<char_type, traits_type>    __iostream_type;
718
719     private:
720       /**
721        *  @if maint
722        *  @doctodo
723        *  @endif
724       */
725       __filebuf_type    _M_filebuf;
726
727     public:
728       // Constructors/destructor:
729       /**
730        *  @brief  Default constructor.
731        *
732        *  Initializes @c sb using its default constructor, and passes
733        *  @c &sb to the base class initializer.  Does not open any files
734        *  (you haven't given it a filename to open).
735       */
736       basic_fstream()
737       : __iostream_type(NULL), _M_filebuf()
738       { this->init(&_M_filebuf); }
739
740       /**
741        *  @brief  Create an input/output file stream.
742        *  @param  s  Null terminated string specifying the filename.
743        *  @param  mode  Open file in specified mode (see std::ios_base).
744        *
745        *  Tip:  When using std::string to hold the filename, you must use
746        *  .c_str() before passing it to this constructor.
747       */
748       explicit
749       basic_fstream(const char* __s,
750                     ios_base::openmode __mode = ios_base::in | ios_base::out)
751       : __iostream_type(NULL), _M_filebuf()
752       {
753         this->init(&_M_filebuf);
754         this->open(__s, __mode);
755       }
756
757       /**
758        *  @brief  The destructor does nothing.
759        *
760        *  The file is closed by the filebuf object, not the formatting
761        *  stream.
762       */
763       ~basic_fstream()
764       { }
765
766       // Members:
767       /**
768        *  @brief  Accessing the underlying buffer.
769        *  @return  The current basic_filebuf buffer.
770        *
771        *  This hides both signatures of std::basic_ios::rdbuf().
772       */
773       __filebuf_type*
774       rdbuf() const
775       { return const_cast<__filebuf_type*>(&_M_filebuf); }
776
777       /**
778        *  @brief  Wrapper to test for an open file.
779        *  @return  @c rdbuf()->is_open()
780       */
781       bool
782       is_open() { return _M_filebuf.is_open(); }
783
784       /**
785        *  @brief  Opens an external file.
786        *  @param  s  The name of the file.
787        *  @param  mode  The open mode flags.
788        *
789        *  Calls @c std::basic_filebuf::open(s,mode).  If that
790        *  function fails, @c failbit is set in the stream's error state.
791        *
792        *  Tip:  When using std::string to hold the filename, you must use
793        *  .c_str() before passing it to this constructor.
794       */
795       void
796       open(const char* __s,
797            ios_base::openmode __mode = ios_base::in | ios_base::out)
798       {
799         if (!_M_filebuf.open(__s, __mode))
800           setstate(ios_base::failbit);
801       }
802
803       /**
804        *  @brief  Close the file.
805        *
806        *  Calls @c std::basic_filebuf::close().  If that function
807        *  fails, @c failbit is set in the stream's error state.
808       */
809       void
810       close()
811       {
812         if (!_M_filebuf.close())
813           setstate(ios_base::failbit);
814       }
815     };
816 } // namespace std
817
818 #ifdef _GLIBCPP_NO_TEMPLATE_EXPORT
819 # define export
820 #endif
821 #ifdef  _GLIBCPP_FULLY_COMPLIANT_HEADERS
822 # include <bits/fstream.tcc>
823 #endif
824
825 #endif