]>
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
);
76 m_lasterror
= wxStream_NOERROR
;
78 m_lasterror
= wxStream_EOF
;
79 if (ret
== wxInvalidOffset
)
81 m_lasterror
= wxStream_READ_ERR
;
88 off_t
wxFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
90 return m_file
->Seek(pos
, mode
);
93 off_t
wxFileInputStream::OnSysTell() const
95 return m_file
->Tell();
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 wxFileOutputStream::wxFileOutputStream(const wxString
& fileName
)
104 m_file
= new wxFile(fileName
, wxFile::write
);
105 m_file_destroy
= TRUE
;
107 if (!m_file
->IsOpened())
109 m_lasterror
= wxSTREAM_WRITE_ERROR
;
114 m_lasterror
= wxSTREAM_WRITE_ERROR
;
118 wxFileOutputStream::wxFileOutputStream(wxFile
& file
)
121 m_file_destroy
= FALSE
;
124 wxFileOutputStream::wxFileOutputStream()
127 m_file_destroy
= FALSE
;
131 wxFileOutputStream::wxFileOutputStream(int fd
)
133 m_file
= new wxFile(fd
);
134 m_file_destroy
= TRUE
;
137 wxFileOutputStream::~wxFileOutputStream()
146 size_t wxFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
148 size_t ret
= m_file
->Write(buffer
, size
);
150 m_lasterror
= wxStream_WRITE_ERR
;
152 m_lasterror
= wxStream_NOERROR
;
156 off_t
wxFileOutputStream::OnSysTell() const
158 return m_file
->Tell();
161 off_t
wxFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
163 return m_file
->Seek(pos
, mode
);
166 void wxFileOutputStream::Sync()
168 wxOutputStream::Sync();
172 size_t wxFileOutputStream::GetSize() const
174 return m_file
->Length();
177 // ----------------------------------------------------------------------------
179 // ----------------------------------------------------------------------------
181 wxFileStream::wxFileStream(const wxString
& fileName
)
182 : wxFileInputStream(fileName
)
184 wxFileOutputStream::m_file
= wxFileInputStream::m_file
;
187 // ----------------------------------------------------------------------------
188 // wxFFileInputStream
189 // ----------------------------------------------------------------------------
191 wxFFileInputStream::wxFFileInputStream(const wxString
& fileName
)
194 m_file
= new wxFFile(fileName
, "rb");
195 m_file_destroy
= TRUE
;
198 wxFFileInputStream::wxFFileInputStream()
201 m_file_destroy
= FALSE
;
205 wxFFileInputStream::wxFFileInputStream(wxFFile
& file
)
208 m_file_destroy
= FALSE
;
211 wxFFileInputStream::wxFFileInputStream(FILE *file
)
213 m_file
= new wxFFile(file
);
214 m_file_destroy
= TRUE
;
217 wxFFileInputStream::~wxFFileInputStream()
223 size_t wxFFileInputStream::GetSize() const
225 return m_file
->Length();
228 size_t wxFFileInputStream::OnSysRead(void *buffer
, size_t size
)
232 ret
= m_file
->Read(buffer
, size
);
235 m_lasterror
= wxStream_EOF
;
236 if (ret
== wxInvalidOffset
)
238 m_lasterror
= wxStream_READ_ERR
;
245 off_t
wxFFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
247 return m_file
->Seek(pos
, mode
);
250 off_t
wxFFileInputStream::OnSysTell() const
252 return m_file
->Tell();
255 // ----------------------------------------------------------------------------
256 // wxFFileOutputStream
257 // ----------------------------------------------------------------------------
259 wxFFileOutputStream::wxFFileOutputStream(const wxString
& fileName
)
261 m_file
= new wxFFile(fileName
, "w+b");
262 m_file_destroy
= TRUE
;
264 if (!m_file
->IsOpened())
266 m_lasterror
= wxSTREAM_WRITE_ERROR
;
271 m_lasterror
= wxSTREAM_WRITE_ERROR
;
275 wxFFileOutputStream::wxFFileOutputStream(wxFFile
& file
)
278 m_file_destroy
= FALSE
;
281 wxFFileOutputStream::wxFFileOutputStream()
284 m_file_destroy
= FALSE
;
288 wxFFileOutputStream::wxFFileOutputStream(FILE *file
)
290 m_file
= new wxFFile(file
);
291 m_file_destroy
= TRUE
;
294 wxFFileOutputStream::~wxFFileOutputStream()
303 size_t wxFFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
305 size_t ret
= m_file
->Write(buffer
, size
);
307 m_lasterror
= wxStream_WRITE_ERR
;
309 m_lasterror
= wxStream_NOERROR
;
313 off_t
wxFFileOutputStream::OnSysTell() const
315 return m_file
->Tell();
318 off_t
wxFFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
320 return m_file
->Seek(pos
, mode
);
323 void wxFFileOutputStream::Sync()
325 wxOutputStream::Sync();
329 size_t wxFFileOutputStream::GetSize() const
331 return m_file
->Length();
334 // ----------------------------------------------------------------------------
336 // ----------------------------------------------------------------------------
338 wxFFileStream::wxFFileStream(const wxString
& fileName
)
339 : wxFFileInputStream(fileName
)
341 wxFFileOutputStream::m_file
= wxFFileInputStream::m_file
;
345 // wxUSE_STREAMS && wxUSE_FILE