Expand PMF_FN_* macros.
[netbsd-mini2440.git] / gnu / lib / libg++ / libg++ / ostream.cc
blobadee1bd267481210040c12c10a7ffd940cd67fff
1 // This may look like C code, but it is really -*- C++ -*-
2 /*
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 *** */
26 #ifdef __GNUG__
27 #pragma implementation
28 #endif
29 #include <stream.h>
30 #include <stdarg.h>
31 #include <values.h>
32 #include <ctype.h>
33 #include <Obstack.h>
35 ostream::ostream(streambuf* s)
36 : bp(s), state(_good), ownbuf(0) {}
38 ostream::ostream(int sz, char* buf)
39 : state(_good), ownbuf(1)
41 if (buf == 0)
43 buf = new char[sz];
44 bp = new streambuf(buf, sz);
45 bp->setbuf(buf, sz);
46 bp->alloc = 1;
48 else
50 bp = new streambuf(buf, sz);
51 bp->alloc = 0;
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);
92 ostream::~ostream()
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...)
124 va_list args;
125 va_start(args, fmt);
126 char buf[BUFSIZ];
127 #ifndef HAVE_VPRINTF
128 FILE b;
129 b._flag = _IOWRT|_IOSTRG;
130 b._ptr = buf;
131 b._cnt = BUFSIZ;
132 _doprnt(fmt, args, &b);
133 putc('\0', &b);
134 #else
135 vsprintf(buf, fmt, args);
136 #endif
137 va_end(args);
138 return put(buf);
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)
163 return put(itoa(n));
166 ostream& ostream::operator<<(unsigned long n)
168 return put(itoa(n));
171 #ifdef __GNUG__
172 #ifndef VMS
173 ostream& ostream::operator<<(long long n)
175 return put(itoa(n));
178 ostream& ostream::operator<<(unsigned long long n)
180 return put(itoa(n));
182 #endif
183 #endif
184 ostream& ostream::operator<<(float n)
186 return put(dtoa(double(n)));
189 ostream& ostream::operator<<(double n)
191 return put(dtoa(n));
194 ostream& ostream::operator<<(const void* p)
196 put("0x");
197 return put(itoa((unsigned long)(p), 16));
201 const char* ostream::name()
203 return bp->name();
206 void ostream::error()
208 bp->error();
211 #if 0 /* BSD 4.4 */
213 ostream cerr(stderr);
214 ostream cout(stdout);
216 #else
218 static char cerrbuf[1];
219 static char coutbuf[BUFSIZE];
221 ostream cerr(2, cerrbuf, 1);
222 ostream cout(1, coutbuf, BUFSIZE);
224 #endif