]> git.saurik.com Git - wxWidgets.git/blame - src/common/wfstream.cpp
Motif compile fixes
[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#ifndef WX_PRECOMP
24 #include "wx/defs.h"
25#endif
26
27#if wxUSE_STREAMS && wxUSE_FILE
28
29#include <stdio.h>
30#include <wx/stream.h>
31#include <wx/wfstream.h>
32
79c3e0e1
GL
33// ----------------------------------------------------------------------------
34// wxFileInputStream
35// ----------------------------------------------------------------------------
36
37wxFileInputStream::wxFileInputStream(const wxString& fileName)
25c70b07 38 : wxInputStream()
3d4c6a21 39{
25c70b07
GL
40 m_file = new wxFile(fileName, wxFile::read);
41 m_file_destroy = TRUE;
6d44bf31 42 m_i_streambuf->SetBufferIO(1024);
3d4c6a21
GL
43}
44
25c70b07
GL
45wxFileInputStream::wxFileInputStream()
46 : wxInputStream()
47{
48 m_file_destroy = FALSE;
49 m_file = NULL;
50}
51
0aca1ded
GL
52wxFileInputStream::wxFileInputStream(wxFile& file)
53{
54 m_file = &file;
55 m_file_destroy = FALSE;
56 m_i_streambuf->SetBufferIO(1024);
57}
58
59wxFileInputStream::wxFileInputStream(int fd)
60{
61 m_file = new wxFile(fd);
62 m_file_destroy = TRUE;
63 m_i_streambuf->SetBufferIO(1024);
64}
65
79c3e0e1 66wxFileInputStream::~wxFileInputStream()
3d4c6a21 67{
25c70b07
GL
68 if (m_file_destroy)
69 delete m_file;
3d4c6a21
GL
70}
71
6d44bf31 72char wxFileInputStream::Peek()
3d4c6a21 73{
6d44bf31 74 return 0;
3d4c6a21
GL
75}
76
84b46c35
GL
77size_t wxFileInputStream::StreamSize() const
78{
79 return m_file->Length();
80}
81
75ed1d15 82size_t wxFileInputStream::OnSysRead(void *buffer, size_t size)
6d44bf31 83{
25c70b07 84 return m_file->Read(buffer, size);
6d44bf31
GL
85}
86
75ed1d15 87off_t wxFileInputStream::OnSysSeek(off_t pos, wxSeekMode mode)
3d4c6a21 88{
25c70b07 89 return m_file->Seek(pos, mode);
79c3e0e1
GL
90}
91
75ed1d15 92off_t wxFileInputStream::OnSysTell() const
79c3e0e1 93{
25c70b07 94 return m_file->Tell();
79c3e0e1
GL
95}
96
97// ----------------------------------------------------------------------------
98// wxFileOutputStream
99// ----------------------------------------------------------------------------
100
101wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
25c70b07
GL
102{
103 m_file = new wxFile(fileName, wxFile::write);
104 m_file_destroy = TRUE;
105 m_o_streambuf->SetBufferIO(1024);
106}
107
84b46c35
GL
108wxFileOutputStream::wxFileOutputStream(wxFile& file)
109{
110 m_file = &file;
111 m_file_destroy = FALSE;
112 m_o_streambuf->SetBufferIO(1024);
113}
114
25c70b07
GL
115wxFileOutputStream::wxFileOutputStream()
116 : wxOutputStream()
79c3e0e1 117{
6d44bf31 118 m_o_streambuf->SetBufferIO(1024);
25c70b07
GL
119 m_file_destroy = FALSE;
120 m_file = NULL;
3d4c6a21
GL
121}
122
0aca1ded
GL
123wxFileOutputStream::wxFileOutputStream(int fd)
124{
125 m_file = new wxFile(fd);
126 m_file_destroy = TRUE;
127 m_o_streambuf->SetBufferIO(1024);
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);
75ed1d15 141 m_lasterror = wxStream_EOF; // TODO
6d44bf31 142 return ret;
79c3e0e1 143}
3d4c6a21 144
75ed1d15 145off_t wxFileOutputStream::OnSysTell() const
79c3e0e1 146{
25c70b07 147 return m_file->Tell();
3d4c6a21
GL
148}
149
75ed1d15 150off_t wxFileOutputStream::OnSysSeek(off_t pos, wxSeekMode mode)
3d4c6a21 151{
25c70b07 152 return m_file->Seek(pos, mode);
3d4c6a21
GL
153}
154
79c3e0e1 155void wxFileOutputStream::Sync()
3d4c6a21 156{
6d44bf31 157 wxOutputStream::Sync();
25c70b07 158 m_file->Flush();
3d4c6a21 159}
84b46c35
GL
160
161size_t wxFileOutputStream::StreamSize() const
162{
163 return m_file->Length();
164}
165
166// ----------------------------------------------------------------------------
167// wxFileStream
168// ----------------------------------------------------------------------------
169wxFileStream::wxFileStream(const wxString& fileName)
170 : wxFileInputStream(fileName), wxFileOutputStream(*wxFileInputStream::m_file)
171{
172}
ce4169a4
RR
173
174#endif
175 // wxUSE_STREAMS && wxUSE_FILE