2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 // $XConsortium: iostream.C /main/4 1996/08/21 15:54:53 drk $
25 #include "utility/c_iostream.h"
30 istream::seekg(streampos delta, ios::seek_dir d)
32 if ( fail() ) return *this;
34 if ( d != ios::beg || sbuf -> seekg(delta) == EOF ) {
46 istream& istream::get(char& c)
48 if ( fail() ) return *this;
50 int i = sbuf -> get();
62 istream::putback(char c)
68 istream& istream::getline(char* b, int lim, char delim)
70 return _getline(b, lim, delim, 1);
73 istream& istream::_getline(char* b, int lim, int delim, int fill_zero)
75 if ( fail() ) return *this;
77 if ( sbuf -> examine() == EOF ) {
82 sbuf -> clear_gcount();
87 for ( count = 0 ; count < lim-1; count++ ) {
91 if ( i == EOF || i == delim ) {
92 //fprintf(stderr, "prematual break in _getline(): i=%d, count = %d\n", i, count);
106 istream::read(char* s, int n)
108 return _getline(s, n+1, EOF, 0);
114 return sbuf -> gcount();
117 istream& istream::operator>>(char& c)
121 if ( (x=sbuf->examine()) == EOF ) return *this;
132 if ( fail() ) return EOF;
134 int c = sbuf->examine();
136 if (c == EOF) set_fail();
138 while (isspace(c) && c != EOF) {
143 if ( c == EOF ) set_fail();
148 istream& istream::operator>>(char* s)
151 if ( (c=eatw()) == EOF ) return *this;
156 c = sbuf -> examine();
157 } while (!isspace(c) && c != EOF) ;
169 istream::operator>>(unsigned short& x)
175 x = (unsigned short)l;
181 istream::operator>>(unsigned int& n)
184 if ( (x=eatw()) == EOF ) return *this;
192 } while (isdigit(x=sbuf->examine()));
204 istream::operator>>(int& x)
216 istream::operator>>(long& n)
220 if ( (x=eatw()) == EOF ) return *this;
229 x = sbuf -> examine();
241 } while (isdigit(x=sbuf->examine()));
252 /////////////////////
254 ostream::operator<<(void* a)
256 if ( fail() ) return *this;
263 ostream::operator<<(const char* str)
271 if (sbuf->put(*str++) == EOF) {
281 ostream::operator<<(char c)
283 if ( fail() ) return *this;
289 ostream::operator<<(int i)
297 ostream::operator<<(unsigned int l)
305 ostream::operator<<(long x)
307 if ( fail() ) return *this;
318 *p++ = '0' + char(x%10);
323 if (sbuf->put(*--p) == EOF) {
334 ostream::operator<< (ostream& (*f)(ostream&))
339 ostream& ostream::put(char c)
341 if ( fail() ) return *this;
346 ostream& ostream::flush()
348 if ( fail() ) return *this;
354 ostream::write(const char* s, int n)
356 for ( int i=0; i<n; i++ ) {
357 if ( sbuf->put(s[i]) == EOF )
363 ostream& endl(ostream& out)
368 istream::istream(streambuf* sb) : ios(sb)
373 ostream::ostream(streambuf* sb) : ios(sb)
378 iostream::iostream(streambuf* sb) : istream(sb), ostream(sb)