]>
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 char wxFileInputStream::Peek()
70 size_t wxFileInputStream::StreamSize() const
72 return m_file
->Length();
75 size_t wxFileInputStream::OnSysRead(void *buffer
, size_t size
)
79 ret
= m_file
->Read(buffer
, size
);
82 m_lasterror
= wxStream_EOF
;
83 if (ret
== wxInvalidOffset
) {
84 m_lasterror
= wxStream_READ_ERR
;
91 off_t
wxFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
93 return m_file
->Seek(pos
, mode
);
96 off_t
wxFileInputStream::OnSysTell() const
98 return m_file
->Tell();
101 // ----------------------------------------------------------------------------
102 // wxFileOutputStream
103 // ----------------------------------------------------------------------------
105 wxFileOutputStream::wxFileOutputStream(const wxString
& fileName
)
107 m_file
= new wxFile(fileName
, wxFile::write
);
108 m_file_destroy
= TRUE
;
111 wxFileOutputStream::wxFileOutputStream(wxFile
& file
)
114 m_file_destroy
= FALSE
;
117 wxFileOutputStream::wxFileOutputStream()
120 m_file_destroy
= FALSE
;
124 wxFileOutputStream::wxFileOutputStream(int fd
)
126 m_file
= new wxFile(fd
);
127 m_file_destroy
= TRUE
;
130 wxFileOutputStream::~wxFileOutputStream()
132 if (m_file_destroy
) {
138 size_t wxFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
140 size_t ret
= m_file
->Write(buffer
, size
);
142 m_lasterror
= wxStream_WRITE_ERR
;
144 m_lasterror
= wxStream_NOERROR
;
148 off_t
wxFileOutputStream::OnSysTell() const
150 return m_file
->Tell();
153 off_t
wxFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
155 return m_file
->Seek(pos
, mode
);
158 void wxFileOutputStream::Sync()
160 wxOutputStream::Sync();
164 size_t wxFileOutputStream::StreamSize() const
166 return m_file
->Length();
169 // ----------------------------------------------------------------------------
171 // ----------------------------------------------------------------------------
172 wxFileStream::wxFileStream(const wxString
& fileName
)
173 : wxFileInputStream(fileName
), wxFileOutputStream(*wxFileInputStream::m_file
)
178 // wxUSE_STREAMS && wxUSE_FILE