]>
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
);
77 m_lasterror
= wxStream_EOF
;
78 if (ret
== wxInvalidOffset
) {
79 m_lasterror
= wxStream_READ_ERR
;
86 off_t
wxFileInputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
88 return m_file
->Seek(pos
, mode
);
91 off_t
wxFileInputStream::OnSysTell() const
93 return m_file
->Tell();
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 wxFileOutputStream::wxFileOutputStream(const wxString
& fileName
)
102 m_file
= new wxFile(fileName
, wxFile::write
);
103 m_file_destroy
= TRUE
;
106 wxFileOutputStream::wxFileOutputStream(wxFile
& file
)
109 m_file_destroy
= FALSE
;
112 wxFileOutputStream::wxFileOutputStream()
115 m_file_destroy
= FALSE
;
119 wxFileOutputStream::wxFileOutputStream(int fd
)
121 m_file
= new wxFile(fd
);
122 m_file_destroy
= TRUE
;
125 wxFileOutputStream::~wxFileOutputStream()
127 if (m_file_destroy
) {
133 size_t wxFileOutputStream::OnSysWrite(const void *buffer
, size_t size
)
135 size_t ret
= m_file
->Write(buffer
, size
);
137 m_lasterror
= wxStream_WRITE_ERR
;
139 m_lasterror
= wxStream_NOERROR
;
143 off_t
wxFileOutputStream::OnSysTell() const
145 return m_file
->Tell();
148 off_t
wxFileOutputStream::OnSysSeek(off_t pos
, wxSeekMode mode
)
150 return m_file
->Seek(pos
, mode
);
153 void wxFileOutputStream::Sync()
155 wxOutputStream::Sync();
159 size_t wxFileOutputStream::GetSize() const
161 return m_file
->Length();
164 // ----------------------------------------------------------------------------
166 // ----------------------------------------------------------------------------
167 wxFileStream::wxFileStream(const wxString
& fileName
)
168 : wxFileInputStream(fileName
), wxFileOutputStream(*wxFileInputStream::m_file
)
173 // wxUSE_STREAMS && wxUSE_FILE