]>
git.saurik.com Git - wxWidgets.git/blob - src/common/wfstream.cpp
296f205b2e3b1f4c703c590e960d29d6302a1e5e
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: "File stream" classes
4 // Author: Julian Smart
8 // Copyright: (c) Guilhem Lavaux
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
)
72 off_t ret
= m_file
->Read(buffer
, size
);
74 // NB: we can't use a switch here because HP-UX CC doesn't allow
75 // switching over long long (which off_t is in 64bit mode)
79 // nothing read, so nothing more to read
80 m_lasterror
= wxSTREAM_EOF
;
82 else if ( ret
== wxInvalidOffset
)
84 m_lasterror
= wxSTREAM_READ_ERROR
;
90 m_lasterror
= wxSTREAM_NO_ERROR
;
96 off_t
wxFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
98 return m_file
->Seek(pos
, mode
);
101 off_t
wxFileInputStream::OnSysTell() const
103 return m_file
->Tell();
106 // ----------------------------------------------------------------------------
107 // wxFileOutputStream
108 // ----------------------------------------------------------------------------
110 wxFileOutputStream::wxFileOutputStream(const wxString
& fileName
)
112 m_file
= new wxFile(fileName
, wxFile::write
);
113 m_file_destroy
= TRUE
;
115 if (!m_file
->IsOpened())
117 m_lasterror
= wxSTREAM_WRITE_ERROR
;
122 m_lasterror
= wxSTREAM_WRITE_ERROR
;
126 wxFileOutputStream::wxFileOutputStream(wxFile
& file
)
129 m_file_destroy
= FALSE
;
132 wxFileOutputStream::wxFileOutputStream()
135 m_file_destroy
= FALSE
;
139 wxFileOutputStream::wxFileOutputStream(int fd
)
141 m_file
= new wxFile(fd
);
142 m_file_destroy
= TRUE
;
145 wxFileOutputStream::~wxFileOutputStream()
154 size_t wxFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
156 size_t ret
= m_file
->Write(buffer
, size
);
158 m_lasterror
= m_file
->Error() ? wxSTREAM_WRITE_ERROR
: wxSTREAM_NO_ERROR
;
163 off_t
wxFileOutputStream::OnSysTell() const
165 return m_file
->Tell();
168 off_t
wxFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
170 return m_file
->Seek(pos
, mode
);
173 void wxFileOutputStream::Sync()
175 wxOutputStream::Sync();
179 size_t wxFileOutputStream::GetSize() const
181 return m_file
->Length();
184 // ----------------------------------------------------------------------------
186 // ----------------------------------------------------------------------------
188 wxFileStream::wxFileStream(const wxString
& fileName
)
189 : wxFileInputStream(fileName
)
191 wxFileOutputStream::m_file
= wxFileInputStream::m_file
;
194 // ----------------------------------------------------------------------------
195 // wxFFileInputStream
196 // ----------------------------------------------------------------------------
198 wxFFileInputStream::wxFFileInputStream(const wxString
& fileName
)
201 m_file
= new wxFFile(fileName
, _T("rb"));
202 m_file_destroy
= TRUE
;
205 wxFFileInputStream::wxFFileInputStream()
208 m_file_destroy
= FALSE
;
212 wxFFileInputStream::wxFFileInputStream(wxFFile
& file
)
215 m_file_destroy
= FALSE
;
218 wxFFileInputStream::wxFFileInputStream(FILE *file
)
220 m_file
= new wxFFile(file
);
221 m_file_destroy
= TRUE
;
224 wxFFileInputStream::~wxFFileInputStream()
230 size_t wxFFileInputStream::GetSize() const
232 return m_file
->Length();
235 size_t wxFFileInputStream::OnSysRead(void *buffer
, size_t size
)
239 ret
= m_file
->Read(buffer
, size
);
242 m_lasterror
= wxSTREAM_EOF
;
243 if (ret
== wxInvalidOffset
)
245 m_lasterror
= wxSTREAM_READ_ERROR
;
252 off_t
wxFFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
255 #pragma message disable intsignchange
257 return ( m_file
->Seek(pos
, mode
) ? m_file
->Tell() : wxInvalidOffset
);
259 #pragma message enable intsignchange
263 off_t
wxFFileInputStream::OnSysTell() const
265 return m_file
->Tell();
268 // ----------------------------------------------------------------------------
269 // wxFFileOutputStream
270 // ----------------------------------------------------------------------------
272 wxFFileOutputStream::wxFFileOutputStream(const wxString
& fileName
)
274 m_file
= new wxFFile(fileName
, _T("w+b"));
275 m_file_destroy
= TRUE
;
277 if (!m_file
->IsOpened())
279 m_lasterror
= wxSTREAM_WRITE_ERROR
;
284 m_lasterror
= wxSTREAM_WRITE_ERROR
;
288 wxFFileOutputStream::wxFFileOutputStream(wxFFile
& file
)
291 m_file_destroy
= FALSE
;
294 wxFFileOutputStream::wxFFileOutputStream()
297 m_file_destroy
= FALSE
;
301 wxFFileOutputStream::wxFFileOutputStream(FILE *file
)
303 m_file
= new wxFFile(file
);
304 m_file_destroy
= TRUE
;
307 wxFFileOutputStream::~wxFFileOutputStream()
316 size_t wxFFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
318 size_t ret
= m_file
->Write(buffer
, size
);
320 m_lasterror
= wxSTREAM_WRITE_ERROR
;
322 m_lasterror
= wxSTREAM_NO_ERROR
;
326 off_t
wxFFileOutputStream::OnSysTell() const
328 return m_file
->Tell();
331 off_t
wxFFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
334 #pragma message disable intsignchange
336 return ( m_file
->Seek(pos
, mode
) ? m_file
->Tell() : wxInvalidOffset
);
338 #pragma message enable intsignchange
342 void wxFFileOutputStream::Sync()
344 wxOutputStream::Sync();
348 size_t wxFFileOutputStream::GetSize() const
350 return m_file
->Length();
353 // ----------------------------------------------------------------------------
355 // ----------------------------------------------------------------------------
357 wxFFileStream::wxFFileStream(const wxString
& fileName
)
358 : wxFFileInputStream(fileName
)
360 wxFFileOutputStream::m_file
= wxFFileInputStream::m_file
;
364 // wxUSE_STREAMS && wxUSE_FILE