]> git.saurik.com Git - wxWidgets.git/blob - src/common/fstream.cpp
* Fixed two memory leaks.
[wxWidgets.git] / src / common / fstream.cpp
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 "fstream.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18 #include <stdio.h>
19 #include <wx/stream.h>
20 #include <wx/fstream.h>
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 // ----------------------------------------------------------------------------
27 // wxFileInputStream
28 // ----------------------------------------------------------------------------
29
30 wxFileInputStream::wxFileInputStream(const wxString& fileName)
31 : wxFile(fileName, read)
32 {
33 m_i_streambuf->SetBufferIO(1024);
34 }
35
36 wxFileInputStream::~wxFileInputStream()
37 {
38 }
39
40 char wxFileInputStream::Peek()
41 {
42 return 0;
43 }
44
45 size_t wxFileInputStream::DoRead(void *buffer, size_t size)
46 {
47 size_t ret = wxFile::Read(buffer, size);
48 m_eof = wxFile::Eof();
49
50 return ret;
51 }
52
53 off_t wxFileInputStream::DoSeekInput(off_t pos, wxSeekMode mode)
54 {
55 return wxFile::Seek(pos, mode);
56 }
57
58 off_t wxFileInputStream::DoTellInput() const
59 {
60 return wxFile::Tell();
61 }
62
63 // ----------------------------------------------------------------------------
64 // wxFileOutputStream
65 // ----------------------------------------------------------------------------
66
67 wxFileOutputStream::wxFileOutputStream(const wxString& fileName)
68 : wxFile(fileName, write)
69 {
70 m_o_streambuf->SetBufferIO(1024);
71 }
72
73 wxFileOutputStream::~wxFileOutputStream()
74 {
75 Sync();
76 }
77
78 size_t wxFileOutputStream::DoWrite(const void *buffer, size_t size)
79 {
80 size_t ret = wxFile::Write(buffer, size);
81 m_bad = wxFile::Error();
82 return ret;
83 }
84
85 off_t wxFileOutputStream::DoTellOutput() const
86 {
87 return wxFile::Tell();
88 }
89
90 off_t wxFileOutputStream::DoSeekOutput(off_t pos, wxSeekMode mode)
91 {
92 return wxFile::Seek(pos, mode);
93 }
94
95 void wxFileOutputStream::Sync()
96 {
97 wxOutputStream::Sync();
98 wxFile::Flush();
99 }
100
101 // ----------------------------------------------------------------------------
102 // wxFileStream
103 // ----------------------------------------------------------------------------
104
105 wxFileStream::wxFileStream(const wxString& fileName)
106 : wxFile(fileName, read_write)
107 {
108 }
109
110 wxFileStream::~wxFileStream()
111 {
112 }