1 // This may look like C code, but it is really -*- C++ -*-
3 Copyright (C) 1989 Free Software Foundation
4 written by Doug Lea (dl@rocky.oswego.edu)
6 This file is part of GNU CC.
8 GNU CC is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY. No author or distributor
10 accepts responsibility to anyone for the consequences of using it
11 or for whether it serves any particular purpose or works at all,
12 unless he says so in writing. Refer to the GNU CC General Public
13 License for full details.
15 Everyone is granted permission to copy, modify and redistribute
16 GNU CC, but only under the conditions described in the
17 GNU CC General Public License. A copy of this license is
18 supposed to have been given to you along with GNU CC so you
19 can know your rights and responsibilities. It should be in a
20 file named COPYING. Among other things, the copyright notice
21 and this notice must be preserved on all copies.
24 /* *** Version 1.2 -- nearly 100% AT&T 1.2 compatible *** */
27 #pragma implementation
35 ostream::ostream(streambuf
* s
)
36 : bp(s
), state(_good
), ownbuf(0) {}
38 ostream::ostream(int sz
, char* buf
)
39 : state(_good
), ownbuf(1)
44 bp
= new streambuf(buf
, sz
);
50 bp
= new streambuf(buf
, sz
);
56 ostream::ostream(const char* filename
, io_mode m
, access_mode a
)
57 : state(_good
), ownbuf(1)
59 bp
= new filebuf(filename
, m
, a
);
62 ostream::ostream(const char* filename
, const char* m
)
63 : state(_good
), ownbuf(1)
65 bp
= new filebuf(filename
, m
);
68 ostream::ostream(int filedesc
, io_mode m
)
69 : state(_good
), ownbuf(1)
71 bp
= new filebuf(filedesc
, m
);
74 ostream::ostream(FILE* fileptr
)
75 : state(_good
), ownbuf(1)
77 bp
= new filebuf(fileptr
);
80 ostream::ostream(int filedesc
)
81 : state(_good
), ownbuf(1)
83 bp
= new filebuf(filedesc
);
86 ostream::ostream(int filedesc
, char* buf
, int buflen
)
87 : state(_good
), ownbuf(1)
89 bp
= new filebuf(filedesc
, buf
, buflen
);
94 if (ownbuf
) delete bp
;
97 ostream
& ostream::open(const char* filename
, io_mode m
, access_mode a
)
99 return failif(bp
->open(filename
, m
, a
) == 0);
102 ostream
& ostream::open(const char* filename
, const char* m
)
104 return failif(bp
->open(filename
, m
) == 0);
107 ostream
& ostream::open(int filedesc
, io_mode m
)
109 return failif(bp
->open(filedesc
, m
) == 0);
112 ostream
& ostream::open(FILE* fileptr
)
114 return failif(bp
->open(fileptr
) == 0);
117 ostream
& ostream::open(const char* filenam
, open_mode m
)
119 return failif(bp
->open(filenam
, m
) == 0);
122 ostream
& ostream::form(const char* fmt
...)
129 b
._flag
= _IOWRT
|_IOSTRG
;
132 _doprnt(fmt
, args
, &b
);
135 vsprintf(buf
, fmt
, args
);
141 ostream
& ostream::operator<<(short n
)
143 return put(itoa(long(n
)));
146 ostream
& ostream::operator<<(unsigned short n
)
148 return put(itoa((unsigned long)(n
)));
151 ostream
& ostream::operator<<(int n
)
153 return put(itoa(long(n
)));
156 ostream
& ostream::operator<<(unsigned int n
)
158 return put(itoa((unsigned long)(n
)));
161 ostream
& ostream::operator<<(long n
)
166 ostream
& ostream::operator<<(unsigned long n
)
173 ostream
& ostream::operator<<(long long n
)
178 ostream
& ostream::operator<<(unsigned long long n
)
184 ostream
& ostream::operator<<(float n
)
186 return put(dtoa(double(n
)));
189 ostream
& ostream::operator<<(double n
)
194 ostream
& ostream::operator<<(const void* p
)
197 return put(itoa((unsigned long)(p
), 16));
201 const char* ostream::name()
206 void ostream::error()
213 ostream
cerr(stderr
);
214 ostream
cout(stdout
);
218 static char cerrbuf
[1];
219 static char coutbuf
[BUFSIZE
];
221 ostream
cerr(2, cerrbuf
, 1);
222 ostream
cout(1, coutbuf
, BUFSIZE
);