]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/common/wfstream.cpp
1. regenerated makefiles
[wxWidgets.git] / src / common / wfstream.cpp
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: fstream.cpp
3// Purpose: "File stream" classes
4// Author: Julian Smart
5// Modified by:
6// Created: 11/07/98
7// RCS-ID: $Id$
8// Copyright: (c) Guilhem Lavaux
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "wfstream.h"
14#endif
15
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifdef __BORLANDC__
20 #pragma hdrstop
21#endif
22
23#if wxUSE_STREAMS && wxUSE_FILE
24
25#include <stdio.h>
26#include "wx/stream.h"
27#include "wx/wfstream.h"
28
29// ----------------------------------------------------------------------------
30// wxFileInputStream
31// ----------------------------------------------------------------------------
32
33wxFileInputStream::wxFileInputStream(const wxString& fileName)
34 : wxInputStream()
35{
36 m_file = new wxFile(fileName, wxFile::read);
37 m_file_destroy = TRUE;
38}
39
40wxFileInputStream::wxFileInputStream()
41 : wxInputStream()
42{
43 m_file_destroy = FALSE;
44 m_file = NULL;
45}
46
47wxFileInputStream::wxFileInputStream(wxFile& file)
48{
49 m_file = &file;
50 m_file_destroy = FALSE;
51}
52
53wxFileInputStream::wxFileInputStream(int fd)
54{
55 m_file = new wxFile(fd);
56 m_file_destroy = TRUE;
57}
58
59wxFileInputStream::~wxFileInputStream()
60{
61 if (m_file_destroy)
62 delete m_file;
63}
64
65char wxFileInputStream::Peek()
66{
67 return 0;
68}
69
70size_t wxFileInputStream::GetSize() const
71{
72 return m_file->Length();
73}
74
75size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
76{
77 off_t ret;
78
79 ret = m_file->Read(buffer, size);
80
81 if (m_file->Eof())
82 m_lasterror = wxStream_EOF;
83 if (ret == wxInvalidOffset) {
84 m_lasterror = wxStream_READ_ERR;
85 ret = 0;
86 }
87
88 return ret;
89}
90
91off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
92{
93 return m_file->Seek(pos, mode);
94}
95
96off_t wxFileInputStream::OnSysTell() const
97{
98 return m_file->Tell();
99}
100
101// ----------------------------------------------------------------------------
102// wxFileOutputStream
103// ----------------------------------------------------------------------------
104
105wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
106{
107 m_file = new wxFile(fileName, wxFile::write);
108 m_file_destroy = TRUE;
109}
110
111wxFileOutputStream::wxFileOutputStream(wxFile& file)
112{
113 m_file = &file;
114 m_file_destroy = FALSE;
115}
116
117wxFileOutputStream::wxFileOutputStream()
118 : wxOutputStream()
119{
120 m_file_destroy = FALSE;
121 m_file = NULL;
122}
123
124wxFileOutputStream::wxFileOutputStream(int fd)
125{
126 m_file = new wxFile(fd);
127 m_file_destroy = TRUE;
128}
129
130wxFileOutputStream::~wxFileOutputStream()
131{
132 if (m_file_destroy) {
133 Sync();
134 delete m_file;
135 }
136}
137
138size_t wxFileOutputStream::OnSysWrite(const void *buffer, size_t size)
139{
140 size_t ret = m_file->Write(buffer, size);
141 if (m_file->Error())
142 m_lasterror = wxStream_WRITE_ERR;
143 else
144 m_lasterror = wxStream_NOERROR;
145 return ret;
146}
147
148off_t wxFileOutputStream::OnSysTell() const
149{
150 return m_file->Tell();
151}
152
153off_t wxFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
154{
155 return m_file->Seek(pos, mode);
156}
157
158void wxFileOutputStream::Sync()
159{
160 wxOutputStream::Sync();
161 m_file->Flush();
162}
163
164size_t wxFileOutputStream::GetSize() const
165{
166 return m_file->Length();
167}
168
169// ----------------------------------------------------------------------------
170// wxFileStream
171// ----------------------------------------------------------------------------
172wxFileStream::wxFileStream(const wxString& fileName)
173 : wxFileInputStream(fileName), wxFileOutputStream(*wxFileInputStream::m_file)
174{
175}
176
177#endif
178 // wxUSE_STREAMS && wxUSE_FILE
179