]>
gcc.gnu.org Git - gcc.git/blob - libstdc++-v3/config/c_io_libio.cc
1747ddb3e6d0beeb2dfde8900a1d832a8a98199c
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 // __basic_file<char> specializations
41 __basic_file
<char>::__basic_file(__c_lock
* __lock
);
45 __basic_file
<char>::overflow(int __c
);
49 __basic_file
<char>::underflow();
53 __basic_file
<char>::uflow();
57 __basic_file
<char>::pbackfail(int __c
);
61 __basic_file
<char>::xsputn(const char* __s
, streamsize __n
);
65 __basic_file
<char>::seekoff(streamoff __off
, ios_base::seekdir __way
,
66 ios_base::openmode __mode
);
70 __basic_file
<char>::seekpos(streamoff __pos
, ios_base::openmode __mode
);
74 __basic_file
<char>::setbuf(char* __b
, int __len
);
78 __basic_file
<char>::sync();
82 __basic_file
<char>::doallocate();
84 // __basic_file<wchar_t> specializations
85 #ifdef _GLIBCPP_USE_WCHAR_T
87 __basic_file
<wchar_t>::__basic_file(__c_lock
* __lock
);
91 __basic_file
<wchar_t>::overflow(int __c
);
95 __basic_file
<wchar_t>::underflow();
99 __basic_file
<wchar_t>::uflow();
103 __basic_file
<wchar_t>::pbackfail(int __c
);
107 __basic_file
<wchar_t>::xsputn(const wchar_t* __s
, streamsize __n
);
111 __basic_file
<wchar_t>::seekoff(streamoff __off
, ios_base::seekdir __way
,
112 ios_base::openmode __mode
);
116 __basic_file
<wchar_t>::seekpos(streamoff __pos
, ios_base::openmode __mode
);
120 __basic_file
<wchar_t>::setbuf(wchar_t* __b
, int __len
);
124 __basic_file
<wchar_t>::sync();
128 __basic_file
<wchar_t>::doallocate();
131 // Generic definitions for __basic_file
132 template<typename _CharT
>
134 __basic_file
<_CharT
>::get_fileno(void)
137 template<typename _CharT
>
138 __basic_file
<_CharT
>::~__basic_file()
139 { _IO_file_finish(this, 0); }
141 template<typename _CharT
>
143 __basic_file
<_CharT
>::_M_open_mode(ios_base::openmode __mode
,
144 int& __p_mode
, int& __rw_mode
,
148 bool __testb
= __mode
& ios_base::binary
;
150 bool __testi
= __mode
& ios_base::in
;
151 bool __testo
= __mode
& ios_base::out
;
152 bool __testt
= __mode
& ios_base::trunc
;
153 bool __testa
= __mode
& ios_base::app
;
155 if (!__testi
&& __testo
&& !__testt
&& !__testa
)
157 __p_mode
= O_WRONLY
| O_TRUNC
| O_CREAT
;
158 __rw_mode
= _IO_NO_READS
;
160 if (!__testi
&& __testo
&& !__testt
&& __testa
)
162 __p_mode
= O_WRONLY
| O_APPEND
| O_CREAT
;
163 __rw_mode
= _IO_NO_READS
| _IO_IS_APPENDING
;
165 if (!__testi
&& __testo
&& __testt
&& !__testa
)
167 __p_mode
= O_WRONLY
| O_TRUNC
| O_CREAT
;
168 __rw_mode
= _IO_NO_READS
;
170 if (__testi
&& !__testo
&& !__testt
&& !__testa
)
173 __rw_mode
= _IO_NO_WRITES
;
175 if (__testi
&& __testo
&& !__testt
&& !__testa
)
180 if (__testi
&& __testo
&& __testt
&& !__testa
)
182 __p_mode
= O_RDWR
| O_TRUNC
| O_CREAT
;
187 __p_mode
|= O_BINARY
;
191 template<typename _CharT
>
192 __basic_file
<_CharT
>*
193 __basic_file
<_CharT
>::sys_open(int __fd
, ios_base::openmode __mode
)
195 __basic_file
* __ret
= NULL
;
197 int __rw_mode
= _IO_NO_READS
+ _IO_NO_WRITES
;
200 _M_open_mode(__mode
, __p_mode
, __rw_mode
, __c_mode
);
202 if (!_IO_file_is_open(this))
205 _flags
&= ~(_IO_NO_READS
+_IO_NO_WRITES
);
206 _flags
|= _IO_DELETE_DONT_CLOSE
;
207 _offset
= _IO_pos_BAD
;
208 int __mask
= _IO_NO_READS
+ _IO_NO_WRITES
+ _IO_IS_APPENDING
;
209 _IO_mask_flags(this, __rw_mode
, __mask
);
215 template<typename _CharT
>
216 __basic_file
<_CharT
>*
217 __basic_file
<_CharT
>::open(const char* __name
, ios_base::openmode __mode
,
220 __basic_file
* __ret
= NULL
;
222 int __rw_mode
= _IO_NO_READS
+ _IO_NO_WRITES
;
225 _M_open_mode(__mode
, __p_mode
, __rw_mode
, __c_mode
);
226 if (!_IO_file_is_open(this))
229 __f
= _IO_file_open(this, __name
, __p_mode
, __prot
, __rw_mode
, 0);
230 __ret
= __f
? this: NULL
;
235 template<typename _CharT
>
237 __basic_file
<_CharT
>::is_open() { return _fileno
>= 0; }
239 template<typename _CharT
>
240 __basic_file
<_CharT
>*
241 __basic_file
<_CharT
>::close()
243 return _IO_file_close_it(this) ? static_cast<__basic_file
*>(NULL
) : this;
246 template<typename _CharT
>
248 __basic_file
<_CharT
>::xsgetn(_CharT
* __s
, streamsize __n
)
249 { return _IO_file_xsgetn(this, __s
, __n
); }
252 template<typename _CharT
>
254 __basic_file
<_CharT
>::sys_read(_CharT
* __s
, streamsize __n
)
255 { return _IO_file_read(this, __s
, __n
); }
258 template<typename _CharT
>
260 __basic_file
<_CharT
>::sys_write(const _CharT
* __s
, streamsize __n
)
261 { return _IO_file_write(this, __s
, __n
); }
264 template<typename _CharT
>
266 __basic_file
<_CharT
>::sys_seek(streamoff __pos
, ios_base::seekdir __way
)
267 { return _IO_file_seek(this, __pos
, __way
); }
270 template<typename _CharT
>
272 __basic_file
<_CharT
>::sys_close()
273 { return _IO_file_close(this); }
276 template<typename _CharT
>
278 __basic_file
<_CharT
>::sys_stat(void* __v
)
279 { return _IO_file_stat(this, __v
); }
282 template<typename _CharT
>
284 __basic_file
<_CharT
>::showmanyc() { return EOF
; }
287 template<typename _CharT
>
289 __basic_file
<_CharT
>::imbue(void* /*__v*/) { }
291 // __basic_file<char> definitions
292 __basic_file
<char>::__basic_file(__c_lock
* __lock
)
297 // Don't set the orientation of the stream when initializing.
298 #ifdef _GLIBCPP_USE_WCHAR_T
299 _IO_no_init(this, 0, 0, &_M_wfile
, 0);
300 #else /* !defined(_GLIBCPP_USE_WCHAR_T) */
301 _IO_no_init(this, 0, 0, NULL
, 0);
302 #endif /* !defined(_GLIBCPP_USE_WCHAR_T) */
303 _IO_JUMPS((_IO_FILE_plus
*) this) = &_IO_file_jumps
;
304 _IO_file_init((_IO_FILE_plus
*)this);
309 __basic_file
<char>::overflow(int __c
)
310 { return _IO_file_overflow(this, __c
); }
314 __basic_file
<char>::underflow()
315 { return _IO_file_underflow(this); }
319 __basic_file
<char>::uflow()
320 { return _IO_default_uflow(this); }
324 __basic_file
<char>::pbackfail(int __c
)
325 { return _IO_default_pbackfail(this, __c
); }
328 __basic_file
<char>::xsputn(const char* __s
, streamsize __n
)
329 { return _IO_file_xsputn(this, __s
, __n
); }
332 __basic_file
<char>::seekoff(streamoff __off
, ios_base::seekdir __way
,
333 ios_base::openmode __mode
)
334 { return _IO_file_seekoff(this, __off
, __way
, __mode
); }
337 __basic_file
<char>::seekpos(streamoff __pos
, ios_base::openmode __mode
)
338 { return _IO_file_seekoff(this, __pos
, ios_base::beg
, __mode
); }
342 __basic_file
<char>::setbuf(char* __b
, int __len
)
343 { return (streambuf
*) _IO_file_setbuf(this,__b
, __len
); }
346 __basic_file
<char>::sync()
347 { return _IO_file_sync(this); }
351 __basic_file
<char>::doallocate()
352 { return _IO_file_doallocate(this); }
354 // __basic_file<wchar_t> definitions
355 #ifdef _GLIBCPP_USE_WCHAR_T
356 __basic_file
<wchar_t>::__basic_file(__c_lock
* __lock
)
361 // Don't set the orientation of the stream when initializing.
362 _IO_no_init(this, 0, 0, &_M_wfile
, &_IO_wfile_jumps
);
363 _IO_JUMPS((_IO_FILE_plus
*) this) = &_IO_wfile_jumps
;
364 _IO_file_init((_IO_FILE_plus
*)this);
366 // In addition, need to allocate the buffer...
367 _IO_wdoallocbuf(this);
368 // Setup initial positions for this buffer...
369 // if (!(_flags & _IO_NO_READS))
370 _IO_wsetg(this, _wide_data
->_IO_buf_base
, _wide_data
->_IO_buf_base
,
371 _wide_data
->_IO_buf_base
);
372 // if (!(_flags & _IO_NO_WRITES))
373 _IO_wsetp(this, _wide_data
->_IO_buf_base
, _wide_data
->_IO_buf_base
);
375 // Setup codecvt bits...
376 _codecvt
= &__c_libio_codecvt
;
378 // Do the same for narrow bits...
379 if (_IO_write_base
== NULL
)
381 _IO_doallocbuf(this);
382 // if (!(_flags & _IO_NO_READS))
383 _IO_setg(this, _IO_buf_base
, _IO_buf_base
, _IO_buf_base
);
384 // if (!(_flags & _IO_NO_WRITES))
385 _IO_setp(this, _IO_buf_base
, _IO_buf_base
);
390 __basic_file
<wchar_t>::overflow(int __c
)
391 { return _IO_wfile_overflow(this, __c
); }
394 __basic_file
<wchar_t>::underflow()
395 { return _IO_wfile_underflow(this); }
399 __basic_file
<wchar_t>::uflow()
400 { return _IO_wdefault_uflow(this); }
404 __basic_file
<wchar_t>::pbackfail(int __c
)
405 { return _IO_wdefault_pbackfail(this, __c
); }
408 __basic_file
<wchar_t>::xsputn(const wchar_t* __s
, streamsize __n
)
409 { return _IO_wfile_xsputn(this, __s
, __n
); }
412 __basic_file
<wchar_t>::seekoff(streamoff __off
, ios_base::seekdir __way
,
413 ios_base::openmode __mode
)
414 { return _IO_wfile_seekoff(this, __off
, __way
, __mode
); }
417 __basic_file
<wchar_t>::seekpos(streamoff __pos
, ios_base::openmode __mode
)
418 { return _IO_wfile_seekoff(this, __pos
, ios_base::beg
, __mode
); }
421 __basic_file
<wchar_t>::setbuf(wchar_t* __b
, int __len
)
422 { return (streambuf
*) _IO_wfile_setbuf(this,__b
, __len
); }
425 __basic_file
<wchar_t>::sync()
426 { return _IO_wfile_sync(this); }
429 __basic_file
<wchar_t>::doallocate()
430 { return _IO_wfile_doallocate(this); }
433 // Need to instantiate base class here for type-info bits, etc
434 template struct __basic_file_base
<char>;
435 template class __basic_file
<char>;
436 #ifdef _GLIBCPP_USE_WCHAR_T
437 template struct __basic_file_base
<wchar_t>;
438 template class __basic_file
<wchar_t>;
This page took 0.057562 seconds and 5 git commands to generate.