* sparc/sol2.h (CPLUSPLUS_CPP_SPEC): Add all of CPP_SPEC instead
[official-gcc.git] / libstdc++-v3 / config / basic_file_libio.h
blob4c6591fd9f64813a5caec269d5cd029b26207cdf
1 // Wrapper of C-language FILE struct -*- C++ -*-
3 // Copyright (C) 2000, 2001 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
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,
19 // USA.
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 <libioP.h>
36 namespace std
38 // __basic_file<char> specializations
39 template<>
40 __basic_file<char>::__basic_file(__c_lock* __lock);
42 template<>
43 int
44 __basic_file<char>::overflow(int __c);
46 template<>
47 int
48 __basic_file<char>::underflow();
50 template<>
51 int
52 __basic_file<char>::uflow();
54 template<>
55 int
56 __basic_file<char>::pbackfail(int __c);
58 template<>
59 streamsize
60 __basic_file<char>::xsputn(const char* __s, streamsize __n);
62 template<>
63 streamoff
64 __basic_file<char>::seekoff(streamoff __off, ios_base::seekdir __way,
65 ios_base::openmode __mode);
67 template<>
68 streamoff
69 __basic_file<char>::seekpos(streamoff __pos, ios_base::openmode __mode);
71 template<>
72 streambuf*
73 __basic_file<char>::setbuf(char* __b, int __len);
75 template<>
76 int
77 __basic_file<char>::sync();
79 template<>
80 int
81 __basic_file<char>::doallocate();
83 // __basic_file<wchar_t> specializations
84 #ifdef _GLIBCPP_USE_WCHAR_T
85 template<>
86 __basic_file<wchar_t>::__basic_file(__c_lock* __lock);
88 template<>
89 int
90 __basic_file<wchar_t>::overflow(int __c);
92 template<>
93 int
94 __basic_file<wchar_t>::underflow();
96 template<>
97 int
98 __basic_file<wchar_t>::uflow();
100 template<>
101 int
102 __basic_file<wchar_t>::pbackfail(int __c);
104 template<>
105 streamsize
106 __basic_file<wchar_t>::xsputn(const wchar_t* __s, streamsize __n);
108 template<>
109 streamoff
110 __basic_file<wchar_t>::seekoff(streamoff __off, ios_base::seekdir __way,
111 ios_base::openmode __mode);
113 template<>
114 streamoff
115 __basic_file<wchar_t>::seekpos(streamoff __pos, ios_base::openmode __mode);
117 template<>
118 streambuf*
119 __basic_file<wchar_t>::setbuf(wchar_t* __b, int __len);
121 template<>
122 int
123 __basic_file<wchar_t>::sync();
125 template<>
126 int
127 __basic_file<wchar_t>::doallocate();
128 #endif
130 template<typename _CharT>
131 __basic_file<_CharT>::~__basic_file()
132 { _IO_file_finish(this, 0); }
134 template<typename _CharT>
135 void
136 __basic_file<_CharT>::_M_open_mode(ios_base::openmode __mode,
137 int& __p_mode, int& __rw_mode,
138 char* /*__c_mode*/)
140 #ifdef O_BINARY
141 bool __testb = __mode & ios_base::binary;
142 #endif
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)
165 __p_mode = O_RDONLY;
166 __rw_mode = _IO_NO_WRITES;
168 if (__testi && __testo && !__testt && !__testa)
170 __p_mode = O_RDWR;
171 __rw_mode = 0;
173 if (__testi && __testo && __testt && !__testa)
175 __p_mode = O_RDWR | O_TRUNC | O_CREAT;
176 __rw_mode = 0;
178 #ifdef O_BINARY
179 if (__testb)
180 __p_mode |= O_BINARY;
181 #endif
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);
191 int __p_mode = 0;
192 int __rw_mode = _IO_NO_READS + _IO_NO_WRITES;
193 char __c_mode[4];
195 _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode);
197 if (!_IO_file_is_open(this))
199 _fileno = __fd;
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);
207 return __ret;
210 template<typename _CharT>
211 __basic_file<_CharT>*
212 __basic_file<_CharT>::open(const char* __name, ios_base::openmode __mode,
213 int __prot)
215 __basic_file* __ret = NULL;
216 int __p_mode = 0;
217 int __rw_mode = _IO_NO_READS + _IO_NO_WRITES;
218 char __c_mode[4];
220 _M_open_mode(__mode, __p_mode, __rw_mode, __c_mode);
221 if (!_IO_file_is_open(this))
223 __c_file_type* __f;
224 __f = _IO_file_open(this, __name, __p_mode, __prot, __rw_mode, 0);
225 __ret = __f ? this: NULL;
227 return __ret;
230 template<typename _CharT>
231 bool
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>
242 streamsize
243 __basic_file<_CharT>::xsgetn(_CharT* __s, streamsize __n)
244 { return _IO_file_xsgetn(this, __s, __n); }
246 // NB: Unused.
247 template<typename _CharT>
248 streamsize
249 __basic_file<_CharT>::sys_read(_CharT* __s, streamsize __n)
250 { return _IO_file_read(this, __s, __n); }
252 // NB: Unused.
253 template<typename _CharT>
254 streamsize
255 __basic_file<_CharT>::sys_write(const _CharT* __s, streamsize __n)
256 { return _IO_file_write(this, __s, __n); }
258 // NB: Unused.
259 template<typename _CharT>
260 streamoff
261 __basic_file<_CharT>::sys_seek(streamoff __pos, ios_base::seekdir __way)
262 { return _IO_file_seek(this, __pos, __way); }
264 // NB: Unused.
265 template<typename _CharT>
266 int
267 __basic_file<_CharT>::sys_close()
268 { return _IO_file_close(this); }
270 // NB: Unused.
271 template<typename _CharT>
272 int
273 __basic_file<_CharT>::sys_stat(void* __v)
274 { return _IO_file_stat(this, __v); }
276 // NB: Unused.
277 template<typename _CharT>
278 int
279 __basic_file<_CharT>::showmanyc() { return EOF; }
281 // NB: Unused.
282 template<typename _CharT>
283 void
284 __basic_file<_CharT>::imbue(void* /*__v*/) { }
285 } // namespace std