]>
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>
36 #include <fcntl.h> // Solaris needs for O_* macros
40 __basic_file::__basic_file(__c_lock
* __lock
)
44 _IO_file_init((_IO_FILE_plus
*) this);
45 _IO_file_attach(this, -1);
49 __basic_file::get_fileno(void)
52 __basic_file::~__basic_file()
57 if (!(_flags
& _IO_DELETE_DONT_CLOSE
))
58 _IO_SYSCLOSE((_IO_FILE
*)this);
60 _IO_default_finish(this, 0);
64 __basic_file::sys_open(int __fd
, ios_base::openmode __mode
)
66 __basic_file
* __retval
= NULL
;
67 bool __testi
= __mode
& ios_base::in
;
68 bool __testo
= __mode
& ios_base::out
;
70 bool __testb
= __mode
& ios_base::binary
;
73 int __rw_mode
= _IO_NO_READS
+ _IO_NO_WRITES
;
78 __rw_mode
= _IO_NO_WRITES
;
82 __p_mode
= O_WRONLY
| O_TRUNC
;
83 __rw_mode
= _IO_NO_READS
;
93 int __mask
= _IO_NO_READS
+ _IO_NO_WRITES
+ _IO_IS_APPENDING
;
94 _flags
= (_flags
& ~__mask
) | (__rw_mode
& __mask
);
95 _IO_link_in((_IO_FILE_plus
*) this);
102 __basic_file::open(const char* __name
, ios_base::openmode __mode
,
105 __basic_file
* __retval
= NULL
;
107 bool __testb
= __mode
& ios_base::binary
;
109 bool __testi
= __mode
& ios_base::in
;
110 bool __testo
= __mode
& ios_base::out
;
111 bool __testt
= __mode
& ios_base::trunc
;
112 bool __testa
= __mode
& ios_base::app
;
114 int __rw_mode
= _IO_NO_READS
+ _IO_NO_WRITES
;
116 if (!__testi
&& __testo
&& !__testt
&& !__testa
)
118 __p_mode
= O_WRONLY
| O_TRUNC
| O_CREAT
;
119 __rw_mode
= _IO_NO_READS
;
121 if (!__testi
&& __testo
&& !__testt
&& __testa
)
123 __p_mode
= O_WRONLY
| O_APPEND
| O_CREAT
;
124 __rw_mode
= _IO_NO_READS
| _IO_IS_APPENDING
;
126 if (!__testi
&& __testo
&& __testt
&& !__testa
)
128 __p_mode
= O_WRONLY
| O_TRUNC
| O_CREAT
;
129 __rw_mode
= _IO_NO_READS
;
131 if (__testi
&& !__testo
&& !__testt
&& !__testa
)
134 __rw_mode
= _IO_NO_WRITES
;
136 if (__testi
&& __testo
&& !__testt
&& !__testa
)
141 if (__testi
&& __testo
&& __testt
&& !__testa
)
143 __p_mode
= O_RDWR
| O_TRUNC
| O_CREAT
;
148 __p_mode
|= O_BINARY
;
150 if (!_IO_file_is_open(this))
152 #if _G_HAVE_IO_FILE_OPEN
154 __f
= _IO_file_open(this, __name
, __p_mode
, __prot
, __rw_mode
, 0);
155 __retval
= __f
? this: NULL
;
157 int __fd
= ::open(__name
, __p_mode
, __prot
);
161 int __mask
= _IO_NO_READS
+ _IO_NO_WRITES
+ _IO_IS_APPENDING
;
162 _flags
= (_flags
& ~__mask
) | (__rw_mode
& __mask
);
172 __basic_file::is_open() { return _fileno
>= 0; }
175 __basic_file::close()
176 { return _IO_file_close_it(this) ? static_cast<__basic_file
*>(NULL
) : this; }
180 __basic_file::overflow(int __c
) { return _IO_file_overflow(this, __c
); }
184 __basic_file::underflow() { return _IO_file_underflow(this); }
188 __basic_file::uflow() { return _IO_default_uflow(this); }
192 __basic_file::pbackfail(int __c
)
193 { return _IO_default_pbackfail(this, __c
); }
196 __basic_file::xsputn(const char* __s
, streamsize __n
)
197 { return _IO_file_xsputn(this, __s
, __n
); }
200 __basic_file::xsgetn(char* __s
, streamsize __n
)
201 { return _IO_default_xsgetn(this, __s
, __n
); }
204 __basic_file::seekoff(streamoff __off
, ios_base::seekdir __way
,
205 ios_base::openmode __mode
)
206 { return _IO_file_seekoff(this, __off
, __way
, __mode
); }
209 __basic_file::seekpos(streamoff __pos
, ios_base::openmode __mode
)
210 { return _IO_file_seekoff(this, __pos
, ios_base::beg
, __mode
); }
214 __basic_file::setbuf(char* __b
, int __len
)
215 { return (streambuf
*) _IO_file_setbuf(this,__b
, __len
); }
219 { return _IO_file_sync(this); }
223 __basic_file::doallocate()
224 { return _IO_file_doallocate(this); }
228 __basic_file::sys_read(char* __s
, streamsize __n
)
229 { return _IO_file_read(this, __s
, __n
); }
233 __basic_file::sys_write(const char* __s
, streamsize __n
)
234 { return _IO_file_write(this, __s
, __n
); }
238 __basic_file::sys_seek(streamoff __pos
, ios_base::seekdir __way
)
239 { return _IO_file_seek(this, __pos
, __way
); }
243 __basic_file::sys_close() { return _IO_file_close(this); }
247 __basic_file::sys_stat(void* __v
) { return _IO_file_stat(this, __v
); }
251 __basic_file::showmanyc() { return EOF
; }
255 __basic_file::imbue(void* /*__v*/) { }
This page took 0.051641 seconds and 6 git commands to generate.