]>
git.saurik.com Git - wxWidgets.git/blob - src/common/wfstream.cpp
4bae72adc7e5c3a80090f382f41d7eca6f131731
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"
27 #if wxUSE_STREAMS && wxUSE_FILE
30 #include <wx/stream.h>
31 #include <wx/wfstream.h>
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
37 wxFileInputStream::wxFileInputStream(const wxString
& fileName
)
40 m_file
= new wxFile(fileName
, wxFile::read
);
41 m_file_destroy
= TRUE
;
44 wxFileInputStream::wxFileInputStream()
47 m_file_destroy
= FALSE
;
51 wxFileInputStream::wxFileInputStream(wxFile
& file
)
54 m_file_destroy
= FALSE
;
57 wxFileInputStream::wxFileInputStream(int fd
)
59 m_file
= new wxFile(fd
);
60 m_file_destroy
= TRUE
;
63 wxFileInputStream::~wxFileInputStream()
69 char wxFileInputStream::Peek()
74 size_t wxFileInputStream::StreamSize() const
76 return m_file
->Length();
79 size_t wxFileInputStream::OnSysRead(void *buffer
, size_t size
)
83 ret
= m_file
->Read(buffer
, size
);
86 m_lasterror
= wxStream_EOF
;
87 if (ret
== wxInvalidOffset
) {
88 m_lasterror
= wxStream_READ_ERR
;
95 off_t
wxFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
97 return m_file
->Seek(pos
, mode
);
100 off_t
wxFileInputStream::OnSysTell() const
102 return m_file
->Tell();
105 // ----------------------------------------------------------------------------
106 // wxFileOutputStream
107 // ----------------------------------------------------------------------------
109 wxFileOutputStream::wxFileOutputStream(const wxString
& fileName
)
111 m_file
= new wxFile(fileName
, wxFile::write
);
112 m_file_destroy
= TRUE
;
115 wxFileOutputStream::wxFileOutputStream(wxFile
& file
)
118 m_file_destroy
= FALSE
;
121 wxFileOutputStream::wxFileOutputStream()
124 m_file_destroy
= FALSE
;
128 wxFileOutputStream::wxFileOutputStream(int fd
)
130 m_file
= new wxFile(fd
);
131 m_file_destroy
= TRUE
;
134 wxFileOutputStream::~wxFileOutputStream()
136 if (m_file_destroy
) {
142 size_t wxFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
144 size_t ret
= m_file
->Write(buffer
, size
);
145 m_lasterror
= wxStream_EOF
; // TODO
149 off_t
wxFileOutputStream::OnSysTell() const
151 return m_file
->Tell();
154 off_t
wxFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
156 return m_file
->Seek(pos
, mode
);
159 void wxFileOutputStream::Sync()
161 wxOutputStream::Sync();
165 size_t wxFileOutputStream::StreamSize() const
167 return m_file
->Length();
170 // ----------------------------------------------------------------------------
172 // ----------------------------------------------------------------------------
173 wxFileStream::wxFileStream(const wxString
& fileName
)
174 : wxFileInputStream(fileName
), wxFileOutputStream(*wxFileInputStream::m_file
)
179 // wxUSE_STREAMS && wxUSE_FILE