]> git.saurik.com Git - wxWidgets.git/blame - src/common/fstream.cpp
Removed streams from VC++ makefile for now; corrected typo in log.h
[wxWidgets.git] / src / common / fstream.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__
13#pragma implementation "fstream.h"
14#endif
15
16#include <wx/object.h>
17#include <stdio.h>
18#include <wx/stream.h>
19#include <wx/fstream.h>
20
21#define BUF_TEMP_SIZE 10000
22
23#if !USE_SHARED_LIBRARY
24IMPLEMENT_CLASS(wxFileStreamBase, wxStream)
25IMPLEMENT_CLASS(wxFileInputStream, wxFileStreamBase)
26IMPLEMENT_CLASS(wxFileOutputStream, wxFileStreamBase)
27IMPLEMENT_CLASS(wxFileStream, wxFileStreamBase)
28#endif
29
30wxFileStreamBase::wxFileStreamBase(const wxString& fileName, int iolimit)
31 : wxStream()
32{
33 char *open_mode;
34
35 switch (iolimit) {
36 case 0:
37 open_mode = "a+";
38 break;
39 case 1:
40 open_mode = "rb";
41 break;
42 case 2:
43 open_mode = "wb";
44 break;
45 }
46 m_file = fopen(fileName, open_mode);
47 fseek(m_file, 0, SEEK_SET);
48
49 m_eof = FALSE;
50 m_bad = FALSE;
51}
52
53wxFileStreamBase::~wxFileStreamBase()
54{
55 fclose(m_file);
56}
57
58wxInputStream& wxFileStreamBase::Read(void *buffer, size_t size)
59{
60 m_lastread = fread(buffer, 1, size, m_file);
61 m_eof = feof(m_file);
62 return *this;
63}
64
65wxOutputStream& wxFileStreamBase::Write(const void *buffer, size_t size)
66{
67 m_lastwrite = fwrite(buffer, 1, size, m_file);
68 m_bad = ferror(m_file) != 0;
69 return *this;
70}
71
72size_t wxFileStreamBase::SeekI(int pos, wxWhenceType whence)
73{
74 int real_whence;
75
76 if (whence == wxBeginPosition)
77 real_whence = SEEK_SET;
78 else if (whence == wxCurrentPosition)
79 real_whence = SEEK_CUR;
80 else if (whence == wxEndPosition)
81 real_whence = SEEK_END;
82
83 fseek(m_file, pos, real_whence);
84 return ftell(m_file);
85}
86
87size_t wxFileStreamBase::TellI() const
88{
89 return ftell(m_file);
90}
91
92size_t wxFileStreamBase::TellO() const
93{
94 return ftell(m_file);
95}
96
97size_t wxFileStreamBase::SeekO(int pos, wxWhenceType whence)
98{
99 return SeekI(pos, whence);
100}
101
102void wxFileStreamBase::Sync()
103{
104 fflush(m_file);
105}