]>
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
;
108 wxFileOutputStream::wxFileOutputStream(wxFile
& file
)
111 m_file_destroy
= FALSE
;
114 wxFileOutputStream::wxFileOutputStream()
117 m_file_destroy
= FALSE
;
121 wxFileOutputStream::wxFileOutputStream(int fd
)
123 m_file
= new wxFile(fd
);
124 m_file_destroy
= TRUE
;
127 wxFileOutputStream::~wxFileOutputStream()
136 size_t wxFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
138 size_t ret
= m_file
->Write(buffer
, size
);
140 m_lasterror
= wxStream_WRITE_ERR
;
142 m_lasterror
= wxStream_NOERROR
;
146 off_t
wxFileOutputStream::OnSysTell() const
148 return m_file
->Tell();
151 off_t
wxFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
153 return m_file
->Seek(pos
, mode
);
156 void wxFileOutputStream::Sync()
158 wxOutputStream::Sync();
162 size_t wxFileOutputStream::GetSize() const
164 return m_file
->Length();
167 // ----------------------------------------------------------------------------
169 // ----------------------------------------------------------------------------
171 wxFileStream::wxFileStream(const wxString
& fileName
)
172 : wxFileInputStream(fileName
)
174 wxFileOutputStream::m_file
= wxFileInputStream::m_file
;
177 // ----------------------------------------------------------------------------
178 // wxFFileInputStream
179 // ----------------------------------------------------------------------------
181 wxFFileInputStream::wxFFileInputStream(const wxString
& fileName
)
184 m_file
= new wxFFile(fileName
, "rb");
185 m_file_destroy
= TRUE
;
188 wxFFileInputStream::wxFFileInputStream()
191 m_file_destroy
= FALSE
;
195 wxFFileInputStream::wxFFileInputStream(wxFFile
& file
)
198 m_file_destroy
= FALSE
;
201 wxFFileInputStream::wxFFileInputStream(FILE *file
)
203 m_file
= new wxFFile(file
);
204 m_file_destroy
= TRUE
;
207 wxFFileInputStream::~wxFFileInputStream()
213 size_t wxFFileInputStream::GetSize() const
215 return m_file
->Length();
218 size_t wxFFileInputStream::OnSysRead(void *buffer
, size_t size
)
222 ret
= m_file
->Read(buffer
, size
);
225 m_lasterror
= wxStream_EOF
;
226 if (ret
== wxInvalidOffset
)
228 m_lasterror
= wxStream_READ_ERR
;
235 off_t
wxFFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
237 return m_file
->Seek(pos
, mode
);
240 off_t
wxFFileInputStream::OnSysTell() const
242 return m_file
->Tell();
245 // ----------------------------------------------------------------------------
246 // wxFFileOutputStream
247 // ----------------------------------------------------------------------------
249 wxFFileOutputStream::wxFFileOutputStream(const wxString
& fileName
)
251 m_file
= new wxFFile(fileName
, "w+b");
252 m_file_destroy
= TRUE
;
255 wxFFileOutputStream::wxFFileOutputStream(wxFFile
& file
)
258 m_file_destroy
= FALSE
;
261 wxFFileOutputStream::wxFFileOutputStream()
264 m_file_destroy
= FALSE
;
268 wxFFileOutputStream::wxFFileOutputStream(FILE *file
)
270 m_file
= new wxFFile(file
);
271 m_file_destroy
= TRUE
;
274 wxFFileOutputStream::~wxFFileOutputStream()
283 size_t wxFFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
285 size_t ret
= m_file
->Write(buffer
, size
);
287 m_lasterror
= wxStream_WRITE_ERR
;
289 m_lasterror
= wxStream_NOERROR
;
293 off_t
wxFFileOutputStream::OnSysTell() const
295 return m_file
->Tell();
298 off_t
wxFFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
300 return m_file
->Seek(pos
, mode
);
303 void wxFFileOutputStream::Sync()
305 wxOutputStream::Sync();
309 size_t wxFFileOutputStream::GetSize() const
311 return m_file
->Length();
314 // ----------------------------------------------------------------------------
316 // ----------------------------------------------------------------------------
318 wxFFileStream::wxFFileStream(const wxString
& fileName
)
319 : wxFFileInputStream(fileName
)
321 wxFFileOutputStream::m_file
= wxFFileInputStream::m_file
;
325 // wxUSE_STREAMS && wxUSE_FILE