1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/***
*fstream.h - definitions/declarations for filebuf and fstream classes
*
* Copyright (c) 1991-1992, Microsoft Corporation. All rights reserved.
*
*Purpose:
* This file defines the classes, values, macros, and functions
* used by the filebuf and fstream classes.
* [AT&T C++]
*
****/
#ifndef _INC_FSTREAM
#define _INC_FSTREAM
#include <iostream.h>
// Force word packing to avoid possible -Zp override
#pragma pack(2)
#pragma warning(disable:4505) // disable unwanted /W4 warning
// #pragma warning(default:4505) // use this to reenable, if necessary
#ifdef M_I86HM
#define _HFAR_ __far
#else
#define _HFAR_
#endif
typedef int filedesc;
class filebuf : public streambuf {
public:
static const int openprot; // default share/prot mode for open
// optional share values for 3rd argument (prot) of open or constructor
static const int sh_compat; // compatibility share mode
static const int sh_none; // exclusive mode no sharing
static const int sh_read; // allow read sharing
static const int sh_write; // allow write sharing
// use (sh_read | sh_write) to allow both read and write sharing
// options for setmode member function
static const int binary;
static const int text;
filebuf();
filebuf(filedesc);
filebuf(filedesc, char _HFAR_ *, int);
~filebuf();
filebuf* attach(filedesc);
filedesc fd() const { return (x_fd==-1) ? EOF : x_fd; }
int is_open() const { return (x_fd!=-1); }
filebuf* open(const char _HFAR_ *, int, int = filebuf::openprot);
filebuf* close();
int setmode(int = filebuf::text);
virtual int overflow(int=EOF);
virtual int underflow();
virtual streambuf* setbuf(char _HFAR_ *, int);
virtual streampos seekoff(streamoff, ios::seek_dir, int);
// virtual streampos seekpos(streampos, int);
virtual int sync();
private:
filedesc x_fd;
int x_fOpened;
};
class ifstream : public istream {
public:
ifstream();
ifstream(const char _HFAR_ *, int =ios::in, int = filebuf::openprot);
ifstream(filedesc);
ifstream(filedesc, char _HFAR_ *, int);
~ifstream();
streambuf * setbuf(char _HFAR_ *, int);
filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
void attach(filedesc);
filedesc fd() const { return rdbuf()->fd(); }
int is_open() const { return rdbuf()->is_open(); }
void open(const char _HFAR_ *, int =ios::in, int = filebuf::openprot);
void close();
int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
};
class ofstream : public ostream {
public:
ofstream();
ofstream(const char _HFAR_ *, int =ios::out, int = filebuf::openprot);
ofstream(filedesc);
ofstream(filedesc, char _HFAR_ *, int);
~ofstream();
streambuf * setbuf(char _HFAR_ *, int);
filebuf* rdbuf() const { return (filebuf*) ios::rdbuf(); }
void attach(filedesc);
filedesc fd() const { return rdbuf()->fd(); }
int is_open() const { return rdbuf()->is_open(); }
void open(const char _HFAR_ *, int =ios::out, int = filebuf::openprot);
void close();
int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
};
class fstream : public iostream {
public:
fstream();
fstream(const char _HFAR_ *, int, int = filebuf::openprot);
fstream(filedesc);
fstream(filedesc, char _HFAR_ *, int);
~fstream();
streambuf * setbuf(char _HFAR_ *, int);
filebuf* rdbuf() const { return (filebuf*) ostream::rdbuf(); }
void attach(filedesc);
filedesc fd() const { return rdbuf()->fd(); }
int is_open() const { return rdbuf()->is_open(); }
void open(const char _HFAR_ *, int, int = filebuf::openprot);
void close();
int setmode(int mode = filebuf::text) { return rdbuf()->setmode(mode); }
};
// manipulators to dynamically change file access mode (filebufs only)
inline ios& binary(ios& _fstrm) \
{ ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::binary); return _fstrm; }
inline ios& text(ios& _fstrm) \
{ ((filebuf*)_fstrm.rdbuf())->setmode(filebuf::text); return _fstrm; }
// Restore default packing
#pragma pack()
#endif
|