]>
gcc.gnu.org Git - gcc.git/blob - libstdc++-v3/config/c_io_stdio.cc
1 // Wrapper of C-language FILE struct -*- C++ -*-
3 // Copyright (C) 2000 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
31 // ISO C++ 14882: 27.8 File-based streams
34 #include <bits/basic_file.h>
38 // Generic definitions for __basic_file
39 template<typename _CharT
>
40 __basic_file
<_CharT
>::__basic_file(__c_lock
* /*__lock*/)
41 : _M_fileno(-1), _M_cfile(NULL
) { }
43 template<typename _CharT
>
45 __basic_file
<_CharT
>::get_fileno(void)
48 template<typename _CharT
>
49 __basic_file
<_CharT
>::~__basic_file()
58 template<typename _CharT
>
60 __basic_file
<_CharT
>::_M_open_mode(ios_base::openmode __mode
,
61 int& /*__p_mode*/, int& /*__rw_mode*/,
64 bool __testb
= __mode
& ios_base::binary
;
65 bool __testi
= __mode
& ios_base::in
;
66 bool __testo
= __mode
& ios_base::out
;
67 bool __testt
= __mode
& ios_base::trunc
;
68 bool __testa
= __mode
& ios_base::app
;
70 if (!__testi
&& __testo
&& !__testt
&& !__testa
)
71 strcpy(__c_mode
, "w");
72 if (!__testi
&& __testo
&& !__testt
&& __testa
)
73 strcpy(__c_mode
, "a");
74 if (!__testi
&& __testo
&& __testt
&& !__testa
)
75 strcpy(__c_mode
, "w");
76 if (__testi
&& !__testo
&& !__testt
&& !__testa
)
77 strcpy(__c_mode
, "r");
78 if (__testi
&& __testo
&& !__testt
&& !__testa
)
79 strcpy(__c_mode
, "r+");
80 if (__testi
&& __testo
&& __testt
&& !__testa
)
81 strcpy(__c_mode
, "w+");
83 strcat(__c_mode
, "b");
86 template<typename _CharT
>
88 __basic_file
<_CharT
>::sys_open(int __fd
, ios_base::openmode __mode
)
90 __basic_file
* __ret
= NULL
;
95 _M_open_mode(__mode
, __p_mode
, __rw_mode
, __c_mode
);
99 if ((_M_cfile
= fdopen(__fd
, __c_mode
)))
108 template<typename _CharT
>
109 __basic_file
<_CharT
>*
110 __basic_file
<_CharT
>::open(const char* __name
, ios_base::openmode __mode
,
113 __basic_file
* __ret
= NULL
;
118 _M_open_mode(__mode
, __p_mode
, __rw_mode
, __c_mode
);
120 if (!this->is_open())
122 if ((_M_cfile
= fopen(__name
, __c_mode
)))
124 _M_fileno
= fileno(_M_cfile
);
131 template<typename _CharT
>
133 __basic_file
<_CharT
>::is_open() { return _M_fileno
>= 0; }
135 template<typename _CharT
>
136 __basic_file
<_CharT
>*
137 __basic_file
<_CharT
>::close()
139 __basic_file
* __retval
= static_cast<__basic_file
*>(NULL
);
140 bool __testopen
= fclose(_M_cfile
);
149 template<typename _CharT
>
151 __basic_file
<_CharT
>::xsgetn(_CharT
* __s
, streamsize __n
)
152 { return fread(__s
, 1, __n
, _M_cfile
); }
154 template<typename _CharT
>
156 __basic_file
<_CharT
>::xsputn(const _CharT
* __s
, streamsize __n
)
157 { return fwrite(__s
, 1, __n
, _M_cfile
); }
159 template<typename _CharT
>
161 __basic_file
<_CharT
>::seekoff(streamoff __off
, ios_base::seekdir __way
,
162 ios_base::openmode
/*__mode*/)
163 { return fseek(_M_cfile
, __off
, __way
); }
165 template<typename _CharT
>
167 __basic_file
<_CharT
>::seekpos(streamoff __pos
,
168 ios_base::openmode
/*__mode*/)
169 { return fseek(_M_cfile
, __pos
, ios_base::beg
); }
171 template<typename _CharT
>
173 __basic_file
<_CharT
>::sync()
174 { return fflush(_M_cfile
); }
177 template<typename _CharT
>
179 __basic_file
<_CharT
>::overflow(int /*__c*/)
183 template<typename _CharT
>
185 __basic_file
<_CharT
>::underflow()
189 template<typename _CharT
>
191 __basic_file
<_CharT
>::uflow()
195 template<typename _CharT
>
197 __basic_file
<_CharT
>::pbackfail(int /*__c*/)
201 template<typename _CharT
>
203 __basic_file
<_CharT
>::setbuf(_CharT
* /*__b*/, int /*__len*/)
204 { return reinterpret_cast<streambuf
*>(this); }
207 template<typename _CharT
>
209 __basic_file
<_CharT
>::doallocate()
213 template<typename _CharT
>
215 __basic_file
<_CharT
>::sys_read(_CharT
* __s
, streamsize __n
)
216 { return fread(__s
, 1, __n
, _M_cfile
); }
219 template<typename _CharT
>
221 __basic_file
<_CharT
>::sys_write(const _CharT
* __s
, streamsize __n
)
222 { return fwrite(__s
, 1, __n
, _M_cfile
); }
225 template<typename _CharT
>
227 __basic_file
<_CharT
>::sys_seek(streamoff __pos
, ios_base::seekdir __way
)
228 { return fseek(_M_cfile
, __pos
, __way
); }
231 template<typename _CharT
>
233 __basic_file
<_CharT
>::sys_close()
234 { return fclose(_M_cfile
); }
237 template<typename _CharT
>
239 __basic_file
<_CharT
>::sys_stat(void* /*__v*/)
243 template<typename _CharT
>
245 __basic_file
<_CharT
>::showmanyc()
249 template<typename _CharT
>
251 __basic_file
<_CharT
>::imbue(void* /*__v*/) { }
253 // Need to instantiate base class here for type-info bits, etc
254 template struct __basic_file_base
<char>;
255 template class __basic_file
<char>;
256 #ifdef _GLIBCPP_USE_WCHAR_T
257 template struct __basic_file_base
<wchar_t>;
258 template class __basic_file
<wchar_t>;
This page took 0.055904 seconds and 6 git commands to generate.