]> git.saurik.com Git - wxWidgets.git/blame - src/common/wfstream.cpp
1. regenerated makefiles
[wxWidgets.git] / src / common / wfstream.cpp
CommitLineData
3d4c6a21
GL
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__
593d4b0d 13#pragma implementation "wfstream.h"
3d4c6a21
GL
14#endif
15
79c3e0e1
GL
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
3d4c6a21 18
79c3e0e1 19#ifdef __BORLANDC__
ce4169a4 20 #pragma hdrstop
79c3e0e1
GL
21#endif
22
ce4169a4
RR
23#if wxUSE_STREAMS && wxUSE_FILE
24
25#include <stdio.h>
d1af991f
RR
26#include "wx/stream.h"
27#include "wx/wfstream.h"
ce4169a4 28
79c3e0e1
GL
29// ----------------------------------------------------------------------------
30// wxFileInputStream
31// ----------------------------------------------------------------------------
32
33wxFileInputStream::wxFileInputStream(const wxString& fileName)
25c70b07 34 : wxInputStream()
3d4c6a21 35{
25c70b07
GL
36 m_file = new wxFile(fileName, wxFile::read);
37 m_file_destroy = TRUE;
3d4c6a21
GL
38}
39
25c70b07
GL
40wxFileInputStream::wxFileInputStream()
41 : wxInputStream()
42{
43 m_file_destroy = FALSE;
44 m_file = NULL;
45}
46
0aca1ded
GL
47wxFileInputStream::wxFileInputStream(wxFile& file)
48{
49 m_file = &file;
50 m_file_destroy = FALSE;
0aca1ded
GL
51}
52
53wxFileInputStream::wxFileInputStream(int fd)
54{
55 m_file = new wxFile(fd);
56 m_file_destroy = TRUE;
0aca1ded
GL
57}
58
79c3e0e1 59wxFileInputStream::~wxFileInputStream()
3d4c6a21 60{
25c70b07
GL
61 if (m_file_destroy)
62 delete m_file;
3d4c6a21
GL
63}
64
6d44bf31 65char wxFileInputStream::Peek()
3d4c6a21 66{
6d44bf31 67 return 0;
3d4c6a21
GL
68}
69
cd25b18c 70size_t wxFileInputStream::GetSize() const
84b46c35
GL
71{
72 return m_file->Length();
73}
74
75ed1d15 75size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
6d44bf31 76{
fae05df5
GL
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;
6d44bf31
GL
89}
90
75ed1d15 91off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
3d4c6a21 92{
25c70b07 93 return m_file->Seek(pos, mode);
79c3e0e1
GL
94}
95
75ed1d15 96off_t wxFileInputStream::OnSysTell() const
79c3e0e1 97{
25c70b07 98 return m_file->Tell();
79c3e0e1
GL
99}
100
101// ----------------------------------------------------------------------------
102// wxFileOutputStream
103// ----------------------------------------------------------------------------
104
105wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
25c70b07
GL
106{
107 m_file = new wxFile(fileName, wxFile::write);
108 m_file_destroy = TRUE;
25c70b07
GL
109}
110
84b46c35
GL
111wxFileOutputStream::wxFileOutputStream(wxFile& file)
112{
113 m_file = &file;
114 m_file_destroy = FALSE;
84b46c35
GL
115}
116
25c70b07
GL
117wxFileOutputStream::wxFileOutputStream()
118 : wxOutputStream()
79c3e0e1 119{
25c70b07
GL
120 m_file_destroy = FALSE;
121 m_file = NULL;
3d4c6a21
GL
122}
123
0aca1ded
GL
124wxFileOutputStream::wxFileOutputStream(int fd)
125{
126 m_file = new wxFile(fd);
127 m_file_destroy = TRUE;
0aca1ded
GL
128}
129
79c3e0e1 130wxFileOutputStream::~wxFileOutputStream()
3d4c6a21 131{
25c70b07
GL
132 if (m_file_destroy) {
133 Sync();
134 delete m_file;
135 }
79c3e0e1 136}
3d4c6a21 137
75ed1d15 138size_t wxFileOutputStream::OnSysWrite(const void *buffer, size_t size)
79c3e0e1 139{
25c70b07 140 size_t ret = m_file->Write(buffer, size);
a324a7bc
GL
141 if (m_file->Error())
142 m_lasterror = wxStream_WRITE_ERR;
143 else
144 m_lasterror = wxStream_NOERROR;
6d44bf31 145 return ret;
79c3e0e1 146}
3d4c6a21 147
75ed1d15 148off_t wxFileOutputStream::OnSysTell() const
79c3e0e1 149{
25c70b07 150 return m_file->Tell();
3d4c6a21
GL
151}
152
75ed1d15 153off_t wxFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
3d4c6a21 154{
25c70b07 155 return m_file->Seek(pos, mode);
3d4c6a21
GL
156}
157
79c3e0e1 158void wxFileOutputStream::Sync()
3d4c6a21 159{
6d44bf31 160 wxOutputStream::Sync();
25c70b07 161 m_file->Flush();
3d4c6a21 162}
84b46c35 163
cd25b18c 164size_t wxFileOutputStream::GetSize() const
84b46c35
GL
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}
ce4169a4
RR
176
177#endif
178 // wxUSE_STREAMS && wxUSE_FILE
cc985fac 179