]>
git.saurik.com Git - wxWidgets.git/blob - src/common/wfstream.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: "File stream" classes
4 // Author: Julian Smart
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "wfstream.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
23 #if wxUSE_STREAMS && wxUSE_FILE
26 #include "wx/stream.h"
27 #include "wx/wfstream.h"
29 // ----------------------------------------------------------------------------
31 // ----------------------------------------------------------------------------
33 wxFileInputStream::wxFileInputStream(const wxString
& fileName
)
36 m_file
= new wxFile(fileName
, wxFile::read
);
37 m_file_destroy
= TRUE
;
40 wxFileInputStream::wxFileInputStream()
43 m_file_destroy
= FALSE
;
47 wxFileInputStream::wxFileInputStream(wxFile
& file
)
50 m_file_destroy
= FALSE
;
53 wxFileInputStream::wxFileInputStream(int fd
)
55 m_file
= new wxFile(fd
);
56 m_file_destroy
= TRUE
;
59 wxFileInputStream::~wxFileInputStream()
65 size_t wxFileInputStream::GetSize() const
67 return m_file
->Length();
70 size_t wxFileInputStream::OnSysRead(void *buffer
, size_t size
)
74 ret
= m_file
->Read(buffer
, size
);
77 m_lasterror
= wxStream_EOF
;
78 if (ret
== wxInvalidOffset
) {
79 m_lasterror
= wxStream_READ_ERR
;
86 off_t
wxFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
88 return m_file
->Seek(pos
, mode
);
91 off_t
wxFileInputStream::OnSysTell() const
93 return m_file
->Tell();
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 wxFileOutputStream::wxFileOutputStream(const wxString
& fileName
)
102 m_file
= new wxFile(fileName
, wxFile::write
);
103 m_file_destroy
= TRUE
;
106 wxFileOutputStream::wxFileOutputStream(wxFile
& file
)
109 m_file_destroy
= FALSE
;
112 wxFileOutputStream::wxFileOutputStream()
115 m_file_destroy
= FALSE
;
119 wxFileOutputStream::wxFileOutputStream(int fd
)
121 m_file
= new wxFile(fd
);
122 m_file_destroy
= TRUE
;
125 wxFileOutputStream::~wxFileOutputStream()
127 if (m_file_destroy
) {
133 size_t wxFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
135 size_t ret
= m_file
->Write(buffer
, size
);
137 m_lasterror
= wxStream_WRITE_ERR
;
139 m_lasterror
= wxStream_NOERROR
;
143 off_t
wxFileOutputStream::OnSysTell() const
145 return m_file
->Tell();
148 off_t
wxFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
150 return m_file
->Seek(pos
, mode
);
153 void wxFileOutputStream::Sync()
155 wxOutputStream::Sync();
159 size_t wxFileOutputStream::GetSize() const
161 return m_file
->Length();
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
167 wxFileStream::wxFileStream(const wxString
& fileName
)
168 : wxFileInputStream(fileName
), wxFileOutputStream(*wxFileInputStream::m_file
)
172 // ----------------------------------------------------------------------------
173 // wxFFileInputStream
174 // ----------------------------------------------------------------------------
176 wxFFileInputStream::wxFFileInputStream(const wxString
& fileName
)
179 m_file
= new wxFFile(fileName
, "r");
180 m_file_destroy
= TRUE
;
183 wxFFileInputStream::wxFFileInputStream()
186 m_file_destroy
= FALSE
;
190 wxFFileInputStream::wxFFileInputStream(wxFFile
& file
)
193 m_file_destroy
= FALSE
;
196 wxFFileInputStream::wxFFileInputStream(FILE *file
)
198 m_file
= new wxFFile(file
);
199 m_file_destroy
= TRUE
;
202 wxFFileInputStream::~wxFFileInputStream()
208 size_t wxFFileInputStream::GetSize() const
210 return m_file
->Length();
213 size_t wxFFileInputStream::OnSysRead(void *buffer
, size_t size
)
217 ret
= m_file
->Read(buffer
, size
);
220 m_lasterror
= wxStream_EOF
;
221 if (ret
== wxInvalidOffset
) {
222 m_lasterror
= wxStream_READ_ERR
;
229 off_t
wxFFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
231 return m_file
->Seek(pos
, mode
);
234 off_t
wxFFileInputStream::OnSysTell() const
236 return m_file
->Tell();
239 // ----------------------------------------------------------------------------
240 // wxFFileOutputStream
241 // ----------------------------------------------------------------------------
243 wxFFileOutputStream::wxFFileOutputStream(const wxString
& fileName
)
245 m_file
= new wxFFile(fileName
, "w+");
246 m_file_destroy
= TRUE
;
249 wxFFileOutputStream::wxFFileOutputStream(wxFFile
& file
)
252 m_file_destroy
= FALSE
;
255 wxFFileOutputStream::wxFFileOutputStream()
258 m_file_destroy
= FALSE
;
262 wxFFileOutputStream::wxFFileOutputStream(FILE *file
)
264 m_file
= new wxFFile(file
);
265 m_file_destroy
= TRUE
;
268 wxFFileOutputStream::~wxFFileOutputStream()
270 if (m_file_destroy
) {
276 size_t wxFFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
278 size_t ret
= m_file
->Write(buffer
, size
);
280 m_lasterror
= wxStream_WRITE_ERR
;
282 m_lasterror
= wxStream_NOERROR
;
286 off_t
wxFFileOutputStream::OnSysTell() const
288 return m_file
->Tell();
291 off_t
wxFFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
293 return m_file
->Seek(pos
, mode
);
296 void wxFFileOutputStream::Sync()
298 wxOutputStream::Sync();
302 size_t wxFFileOutputStream::GetSize() const
304 return m_file
->Length();
307 // ----------------------------------------------------------------------------
309 // ----------------------------------------------------------------------------
310 wxFFileStream::wxFFileStream(const wxString
& fileName
)
311 : wxFFileInputStream(fileName
), wxFFileOutputStream(*wxFFileInputStream::m_file
)
315 // wxUSE_STREAMS && wxUSE_FILE