1 // Wrapper of C-language FILE struct -*- C++ -*-
3 // Copyright (C) 2000, 2001 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
38 // __basic_file<char> specializations
40 __basic_file
<char>::__basic_file(__c_lock
* __lock
);
44 __basic_file
<char>::overflow(int __c
);
48 __basic_file
<char>::underflow();
52 __basic_file
<char>::uflow();
56 __basic_file
<char>::pbackfail(int __c
);
60 __basic_file
<char>::xsputn(const char* __s
, streamsize __n
);
64 __basic_file
<char>::seekoff(streamoff __off
, ios_base::seekdir __way
,
65 ios_base::openmode __mode
);
69 __basic_file
<char>::seekpos(streamoff __pos
, ios_base::openmode __mode
);
73 __basic_file
<char>::setbuf(char* __b
, int __len
);
77 __basic_file
<char>::sync();
81 __basic_file
<char>::doallocate();
83 // __basic_file<wchar_t> specializations
84 #ifdef _GLIBCPP_USE_WCHAR_T
86 __basic_file
<wchar_t>::__basic_file(__c_lock
* __lock
);
90 __basic_file
<wchar_t>::overflow(int __c
);
94 __basic_file
<wchar_t>::underflow();
98 __basic_file
<wchar_t>::uflow();
102 __basic_file
<wchar_t>::pbackfail(int __c
);
106 __basic_file
<wchar_t>::xsputn(const wchar_t* __s
, streamsize __n
);
110 __basic_file
<wchar_t>::seekoff(streamoff __off
, ios_base::seekdir __way
,
111 ios_base::openmode __mode
);
115 __basic_file
<wchar_t>::seekpos(streamoff __pos
, ios_base::openmode __mode
);
119 __basic_file
<wchar_t>::setbuf(wchar_t* __b
, int __len
);
123 __basic_file
<wchar_t>::sync();
127 __basic_file
<wchar_t>::doallocate();
130 template<typename _CharT
>
131 __basic_file
<_CharT
>::~__basic_file()
132 { _IO_file_finish(this, 0); }
134 template<typename _CharT
>
136 __basic_file
<_CharT
>::_M_open_mode(ios_base::openmode __mode
,
137 int& __p_mode
, int& __rw_mode
,
141 bool __testb
= __mode
& ios_base::binary
;
143 bool __testi
= __mode
& ios_base::in
;
144 bool __testo
= __mode
& ios_base::out
;
145 bool __testt
= __mode
& ios_base::trunc
;
146 bool __testa
= __mode
& ios_base::app
;
148 if (!__testi
&& __testo
&& !__testt
&& !__testa
)
150 __p_mode
= O_WRONLY
| O_TRUNC
| O_CREAT
;
151 __rw_mode
= _IO_NO_READS
;
153 if (!__testi
&& __testo
&& !__testt
&& __testa
)
155 __p_mode
= O_WRONLY
| O_APPEND
| O_CREAT
;
156 __rw_mode
= _IO_NO_READS
| _IO_IS_APPENDING
;
158 if (!__testi
&& __testo
&& __testt
&& !__testa
)
160 __p_mode
= O_WRONLY
| O_TRUNC
| O_CREAT
;
161 __rw_mode
= _IO_NO_READS
;
163 if (__testi
&& !__testo
&& !__testt
&& !__testa
)
166 __rw_mode
= _IO_NO_WRITES
;
168 if (__testi
&& __testo
&& !__testt
&& !__testa
)
173 if (__testi
&& __testo
&& __testt
&& !__testa
)
175 __p_mode
= O_RDWR
| O_TRUNC
| O_CREAT
;
180 __p_mode
|= O_BINARY
;
184 template<typename _CharT
>
185 __basic_file
<_CharT
>*
186 __basic_file
<_CharT
>::sys_open(__c_file_type
* __f
,
187 ios_base::openmode __mode
)
189 __basic_file
* __ret
= NULL
;
190 int __fd
= fileno(__f
);
192 int __rw_mode
= _IO_NO_READS
+ _IO_NO_WRITES
;
195 _M_open_mode(__mode
, __p_mode
, __rw_mode
, __c_mode
);
197 if (!_IO_file_is_open(this))
200 _flags
&= ~(_IO_NO_READS
+ _IO_NO_WRITES
);
201 _flags
|= _IO_DELETE_DONT_CLOSE
;
202 _offset
= _IO_pos_BAD
;
203 int __mask
= _IO_NO_READS
+ _IO_NO_WRITES
+ _IO_IS_APPENDING
;
204 _IO_mask_flags(this, __rw_mode
, __mask
);
210 template<typename _CharT
>
211 __basic_file
<_CharT
>*
212 __basic_file
<_CharT
>::open(const char* __name
, ios_base::openmode __mode
,
215 __basic_file
* __ret
= NULL
;
217 int __rw_mode
= _IO_NO_READS
+ _IO_NO_WRITES
;
220 _M_open_mode(__mode
, __p_mode
, __rw_mode
, __c_mode
);
221 if (!_IO_file_is_open(this))
224 __f
= _IO_file_open(this, __name
, __p_mode
, __prot
, __rw_mode
, 0);
225 __ret
= __f
? this: NULL
;
230 template<typename _CharT
>
232 __basic_file
<_CharT
>::is_open() { return _fileno
>= 0; }
234 template<typename _CharT
>
235 __basic_file
<_CharT
>*
236 __basic_file
<_CharT
>::close()
238 return _IO_file_close_it(this) ? static_cast<__basic_file
*>(NULL
) : this;
241 template<typename _CharT
>
243 __basic_file
<_CharT
>::xsgetn(_CharT
* __s
, streamsize __n
)
244 { return _IO_file_xsgetn(this, __s
, __n
); }
247 template<typename _CharT
>
249 __basic_file
<_CharT
>::sys_read(_CharT
* __s
, streamsize __n
)
250 { return _IO_file_read(this, __s
, __n
); }
253 template<typename _CharT
>
255 __basic_file
<_CharT
>::sys_write(const _CharT
* __s
, streamsize __n
)
256 { return _IO_file_write(this, __s
, __n
); }
259 template<typename _CharT
>
261 __basic_file
<_CharT
>::sys_seek(streamoff __pos
, ios_base::seekdir __way
)
262 { return _IO_file_seek(this, __pos
, __way
); }
265 template<typename _CharT
>
267 __basic_file
<_CharT
>::sys_close()
268 { return _IO_file_close(this); }
271 template<typename _CharT
>
273 __basic_file
<_CharT
>::sys_stat(void* __v
)
274 { return _IO_file_stat(this, __v
); }
277 template<typename _CharT
>
279 __basic_file
<_CharT
>::showmanyc() { return EOF
; }
282 template<typename _CharT
>
284 __basic_file
<_CharT
>::imbue(void* /*__v*/) { }