|
|
1.1 root 1: /*ident "@(#)ctrans:lib/stream/fstream.c 1.1.2.2" */
2: /**************************************************************************
3: Copyright (c) 1984 AT&T
4: All Rights Reserved
5:
6: THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T
7:
8: The copyright notice above does not evidence any
9: actual or intended publication of such source code.
10:
11: fstream.c:
12:
13: *****************************************************************************/
14:
15: #include <iostream.h>
16: #include <fstream.h>
17:
18: static const int ios_atend = ios::ate ;
19: static const int ios_input = ios::in ;
20: static const int ios_output = ios::out ;
21: static const int ios_append = ios::app ;
22: static const int seek_cur = ios::cur ;
23: static const int seek_end = ios::end ;
24: static const int seek_beg = ios::beg ;
25:
26: fstreambase::fstreambase() { init(&buf) ; }
27:
28: fstreambase::fstreambase(const char* name, int mode, int prot)
29: {
30: init(&buf) ;
31: open(name,mode,prot) ;
32: }
33:
34: fstreambase::fstreambase(int fd)
35: : buf(fd)
36: {
37: init(&buf) ;
38: }
39:
40: fstreambase::fstreambase(int fd, char* p, int l)
41: : buf(fd,p,l)
42: {
43: init(&buf) ;
44: }
45:
46: static inline void fstreambase::verify(int ok)
47: {
48: if ( ok ) clear(0) ;
49: else setstate(ios::failbit) ;
50: }
51:
52: void fstreambase::setbuf(char* p, int len)
53: {
54: verify(buf.setbuf(p,len) != 0 ) ;
55: }
56:
57: void fstreambase::open(const char* name, int mode, int prot)
58: {
59: verify(buf.open(name,mode,prot) != 0 ) ;
60: }
61:
62: void fstreambase::attach(int fd )
63: {
64: verify(buf.attach(fd) != 0 ) ;
65: }
66:
67: void fstreambase::close()
68: {
69: verify(buf.close() != (filebuf*)0 ) ;
70: }
71:
72: fstreambase::~fstreambase() { }
73:
74: ifstream::ifstream() { }
75: ifstream::ifstream(const char* name, int mode, int prot)
76: : fstreambase(name,mode|ios_input,prot) { }
77: ifstream::ifstream(int fd) : fstreambase(fd) { }
78: ifstream::ifstream(int fd, char* p, int l) : fstreambase(fd,p,l) { }
79: ifstream::~ifstream() { }
80:
81: void ifstream::open(const char* name, int mode, int prot)
82: {
83: verify(rdbuf()->open(name,mode|ios_input,prot) != (filebuf*)0 ) ;
84: }
85:
86: ofstream::ofstream() { }
87: ofstream::ofstream(const char* name, int mode, int prot)
88: : fstreambase(name,mode|ios_output,prot) { }
89: ofstream::ofstream(int fd) : fstreambase(fd) { }
90: ofstream::ofstream(int fd, char* p, int l) : fstreambase(fd,p,l) { }
91: ofstream::~ofstream() { }
92: void ofstream::open(const char* name, int mode, int prot)
93: {
94: verify(rdbuf()->open(name,mode|ios_output,prot) != (filebuf*)0 ) ;
95: }
96:
97: fstream::fstream() { }
98: fstream::fstream(const char* name, int mode, int prot)
99: : fstreambase(name,mode,prot) { }
100: fstream::fstream(int fd) : fstreambase(fd) { }
101: fstream::fstream(int fd, char* p, int l) : fstreambase(fd,p,l) { }
102: fstream::~fstream() { }void fstream::open(const char* name, int mode, int prot)
103: {
104: verify(rdbuf()->open(name,mode,prot) != (filebuf*)0 ) ;
105: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.