00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 #include <fstream>
00031 
00032 namespace __gnu_cxx
00033 {
00034   template<typename _CharT, typename _Traits = std::char_traits<_CharT> >
00035     class stdio_filebuf : public std::basic_filebuf<_CharT, _Traits>
00036     {
00037     public:
00038       
00039       typedef _CharT                                char_type;
00040       typedef _Traits                               traits_type;
00041       typedef typename traits_type::int_type        int_type;
00042       typedef typename traits_type::pos_type        pos_type;
00043       typedef typename traits_type::off_type        off_type;
00044       
00045     protected:
00046       
00047       char_type         _M_unbuf[4];
00048       
00049     public:
00050       stdio_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, 
00051             int_type __size);
00052 
00053       stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, 
00054             int_type __size = static_cast<int_type>(BUFSIZ));
00055 
00056       virtual
00057       ~stdio_filebuf();
00058 
00059       int
00060       fd()
00061       { return _M_file.fd(); }
00062     };
00063 
00064   template<typename _CharT, typename _Traits>
00065     stdio_filebuf<_CharT, _Traits>::~stdio_filebuf()
00066     { }
00067 
00068   template<typename _CharT, typename _Traits>
00069     stdio_filebuf<_CharT, _Traits>::
00070     stdio_filebuf(int __fd, std::ios_base::openmode __mode, bool __del, 
00071           int_type __size)
00072     {
00073       _M_file.sys_open(__fd, __mode, __del);
00074       if (this->is_open())
00075     {
00076       _M_mode = __mode;
00077       _M_buf_size_opt = __size;
00078       
00079       if (__size > 0 && __size < 4)
00080         {
00081           _M_buf = _M_unbuf;
00082           _M_buf_size = __size;
00083         }
00084       else
00085         _M_allocate_internal_buffer();
00086       
00087       _M_set_indeterminate();
00088     }
00089     }
00090 
00091   template<typename _CharT, typename _Traits>
00092     stdio_filebuf<_CharT, _Traits>::
00093     stdio_filebuf(std::__c_file* __f, std::ios_base::openmode __mode, 
00094           int_type __size)
00095     {
00096       _M_file.sys_open(__f, __mode);
00097       if (this->is_open())
00098     {
00099       _M_mode = __mode;
00100       _M_buf_size_opt = __size;
00101       
00102       if (__size > 0 && __size < 4)
00103         {
00104           _M_buf = _M_unbuf;
00105           _M_buf_size = __size;
00106         }
00107       else
00108         _M_allocate_internal_buffer();
00109       
00110       _M_set_indeterminate();
00111     }
00112     }
00113 }