]>
gcc.gnu.org Git - gcc.git/blob - libstdc++-v3/config/c_io_libio.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>
39 // Need to instantiate base class here for type-info bits, etc
40 template struct __basic_file_base
<char>;
41 template struct __basic_file_base
<wchar_t>;
43 // Generic definitions for __basic_file
44 template<typename _CharT
>
46 __basic_file
<_CharT
>::get_fileno(void)
49 template<typename _CharT
>
50 __basic_file
<_CharT
>::~__basic_file()
51 { _IO_file_finish(this, 0); }
53 template<typename _CharT
>
55 __basic_file
<_CharT
>::_M_open_mode(ios_base::openmode __mode
,
56 int& __p_mode
, int& __rw_mode
)
59 bool __testb
= __mode
& ios_base::binary
;
61 bool __testi
= __mode
& ios_base::in
;
62 bool __testo
= __mode
& ios_base::out
;
63 bool __testt
= __mode
& ios_base::trunc
;
64 bool __testa
= __mode
& ios_base::app
;
66 if (!__testi
&& __testo
&& !__testt
&& !__testa
)
68 __p_mode
= O_WRONLY
| O_TRUNC
| O_CREAT
;
69 __rw_mode
= _IO_NO_READS
;
71 if (!__testi
&& __testo
&& !__testt
&& __testa
)
73 __p_mode
= O_WRONLY
| O_APPEND
| O_CREAT
;
74 __rw_mode
= _IO_NO_READS
| _IO_IS_APPENDING
;
76 if (!__testi
&& __testo
&& __testt
&& !__testa
)
78 __p_mode
= O_WRONLY
| O_TRUNC
| O_CREAT
;
79 __rw_mode
= _IO_NO_READS
;
81 if (__testi
&& !__testo
&& !__testt
&& !__testa
)
84 __rw_mode
= _IO_NO_WRITES
;
86 if (__testi
&& __testo
&& !__testt
&& !__testa
)
91 if (__testi
&& __testo
&& __testt
&& !__testa
)
93 __p_mode
= O_RDWR
| O_TRUNC
| O_CREAT
;
102 template<typename _CharT
>
103 __basic_file
<_CharT
>*
104 __basic_file
<_CharT
>::sys_open(int __fd
, ios_base::openmode __mode
)
106 __basic_file
* __ret
= NULL
;
108 int __rw_mode
= _IO_NO_READS
+ _IO_NO_WRITES
;
110 _M_open_mode(__mode
, __p_mode
, __rw_mode
);
112 if (!_IO_file_is_open(this))
115 _flags
&= ~(_IO_NO_READS
+_IO_NO_WRITES
);
116 _flags
|= _IO_DELETE_DONT_CLOSE
;
117 _offset
= _IO_pos_BAD
;
118 int __mask
= _IO_NO_READS
+ _IO_NO_WRITES
+ _IO_IS_APPENDING
;
119 _IO_mask_flags(this, __rw_mode
, __mask
);
125 template<typename _CharT
>
126 __basic_file
<_CharT
>*
127 __basic_file
<_CharT
>::open(const char* __name
, ios_base::openmode __mode
,
130 __basic_file
* __ret
= NULL
;
132 int __rw_mode
= _IO_NO_READS
+ _IO_NO_WRITES
;
134 _M_open_mode(__mode
, __p_mode
, __rw_mode
);
135 if (!_IO_file_is_open(this))
138 __f
= _IO_file_open(this, __name
, __p_mode
, __prot
, __rw_mode
, 0);
139 __ret
= __f
? this: NULL
;
144 template<typename _CharT
>
146 __basic_file
<_CharT
>::is_open() { return _fileno
>= 0; }
148 template<typename _CharT
>
149 __basic_file
<_CharT
>*
150 __basic_file
<_CharT
>::close()
152 return _IO_file_close_it(this) ? static_cast<__basic_file
*>(NULL
) : this;
155 template<typename _CharT
>
157 __basic_file
<_CharT
>::xsgetn(_CharT
* __s
, streamsize __n
)
158 { return _IO_file_xsgetn(this, __s
, __n
); }
161 template<typename _CharT
>
163 __basic_file
<_CharT
>::sys_read(_CharT
* __s
, streamsize __n
)
164 { return _IO_file_read(this, __s
, __n
); }
167 template<typename _CharT
>
169 __basic_file
<_CharT
>::sys_write(const _CharT
* __s
, streamsize __n
)
170 { return _IO_file_write(this, __s
, __n
); }
173 template<typename _CharT
>
175 __basic_file
<_CharT
>::sys_seek(streamoff __pos
, ios_base::seekdir __way
)
176 { return _IO_file_seek(this, __pos
, __way
); }
179 template<typename _CharT
>
181 __basic_file
<_CharT
>::sys_close()
182 { return _IO_file_close(this); }
185 template<typename _CharT
>
187 __basic_file
<_CharT
>::sys_stat(void* __v
)
188 { return _IO_file_stat(this, __v
); }
191 template<typename _CharT
>
193 __basic_file
<_CharT
>::showmanyc() { return EOF
; }
196 template<typename _CharT
>
198 __basic_file
<_CharT
>::imbue(void* /*__v*/) { }
200 // __basic_file<char> definitions
201 __basic_file
<char>::__basic_file(__c_lock
* __lock
)
206 // Don't set the orientation of the stream when initializing.
207 #ifdef _GLIBCPP_USE_WCHAR_T
208 _IO_no_init(this, 0, 0, &_M_wfile
, 0);
209 #else /* !defined(_GLIBCPP_USE_WCHAR_T) */
210 _IO_no_init(this, 0, 0, NULL
, 0);
211 #endif /* !defined(_GLIBCPP_USE_WCHAR_T) */
212 _IO_JUMPS((_IO_FILE_plus
*) this) = &_IO_file_jumps
;
213 _IO_file_init((_IO_FILE_plus
*)this);
218 __basic_file
<char>::overflow(int __c
)
219 { return _IO_file_overflow(this, __c
); }
223 __basic_file
<char>::underflow()
224 { return _IO_file_underflow(this); }
228 __basic_file
<char>::uflow()
229 { return _IO_default_uflow(this); }
233 __basic_file
<char>::pbackfail(int __c
)
234 { return _IO_default_pbackfail(this, __c
); }
237 __basic_file
<char>::xsputn(const char* __s
, streamsize __n
)
238 { return _IO_file_xsputn(this, __s
, __n
); }
241 __basic_file
<char>::seekoff(streamoff __off
, ios_base::seekdir __way
,
242 ios_base::openmode __mode
)
243 { return _IO_file_seekoff(this, __off
, __way
, __mode
); }
246 __basic_file
<char>::seekpos(streamoff __pos
, ios_base::openmode __mode
)
247 { return _IO_file_seekoff(this, __pos
, ios_base::beg
, __mode
); }
251 __basic_file
<char>::setbuf(char* __b
, int __len
)
252 { return (streambuf
*) _IO_file_setbuf(this,__b
, __len
); }
255 __basic_file
<char>::sync()
256 { return _IO_file_sync(this); }
260 __basic_file
<char>::doallocate()
261 { return _IO_file_doallocate(this); }
263 template class __basic_file
<char>;
265 // __basic_file<wchar_t> definitions
266 #ifdef _GLIBCPP_USE_WCHAR_T
267 __basic_file
<wchar_t>::__basic_file(__c_lock
* __lock
)
272 // Don't set the orientation of the stream when initializing.
273 _IO_no_init(this, 0, 0, &_M_wfile
, &_IO_wfile_jumps
);
274 _IO_JUMPS((_IO_FILE_plus
*) this) = &_IO_wfile_jumps
;
275 _IO_file_init((_IO_FILE_plus
*)this);
277 // In addition, need to allocate the buffer...
278 _IO_wdoallocbuf(this);
279 // Setup initial positions for this buffer...
280 // if (!(_flags & _IO_NO_READS))
281 _IO_wsetg(this, _wide_data
->_IO_buf_base
, _wide_data
->_IO_buf_base
,
282 _wide_data
->_IO_buf_base
);
283 // if (!(_flags & _IO_NO_WRITES))
284 _IO_wsetp(this, _wide_data
->_IO_buf_base
, _wide_data
->_IO_buf_base
);
286 // Setup codecvt bits...
287 _codecvt
= &__c_libio_codecvt
;
289 // Do the same for narrow bits...
290 if (_IO_write_base
== NULL
)
292 _IO_doallocbuf(this);
293 // if (!(_flags & _IO_NO_READS))
294 _IO_setg(this, _IO_buf_base
, _IO_buf_base
, _IO_buf_base
);
295 // if (!(_flags & _IO_NO_WRITES))
296 _IO_setp(this, _IO_buf_base
, _IO_buf_base
);
301 __basic_file
<wchar_t>::overflow(int __c
)
302 { return _IO_wfile_overflow(this, __c
); }
305 __basic_file
<wchar_t>::underflow()
306 { return _IO_wfile_underflow(this); }
310 __basic_file
<wchar_t>::uflow()
311 { return _IO_wdefault_uflow(this); }
315 __basic_file
<wchar_t>::pbackfail(int __c
)
316 { return _IO_wdefault_pbackfail(this, __c
); }
319 __basic_file
<wchar_t>::xsputn(const wchar_t* __s
, streamsize __n
)
320 { return _IO_wfile_xsputn(this, __s
, __n
); }
323 __basic_file
<wchar_t>::seekoff(streamoff __off
, ios_base::seekdir __way
,
324 ios_base::openmode __mode
)
325 { return _IO_wfile_seekoff(this, __off
, __way
, __mode
); }
328 __basic_file
<wchar_t>::seekpos(streamoff __pos
, ios_base::openmode __mode
)
329 { return _IO_wfile_seekoff(this, __pos
, ios_base::beg
, __mode
); }
332 __basic_file
<wchar_t>::setbuf(wchar_t* __b
, int __len
)
333 { return (streambuf
*) _IO_wfile_setbuf(this,__b
, __len
); }
336 __basic_file
<wchar_t>::sync()
337 { return _IO_wfile_sync(this); }
340 __basic_file
<wchar_t>::doallocate()
341 { return _IO_wfile_doallocate(this); }
343 template class __basic_file
<wchar_t>;
This page took 0.064664 seconds and 6 git commands to generate.