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();
86 for ( int count = 0 ; count < lim-1; count++ ) {
90 if ( i == EOF || i == delim ) {
91 //fprintf(stderr, "prematual break in _getline(): i=%d, count = %d\n", i, count);
105 istream::read(char* s, int n)
107 return _getline(s, n+1, EOF, 0);
113 return sbuf -> gcount();
116 istream& istream::operator>>(char& c)
120 if ( (x=sbuf->examine()) == EOF ) return *this;
131 if ( fail() ) return EOF;
133 int c = sbuf->examine();
135 if (c == EOF) set_fail();
137 while (isspace(c) && c != EOF) {
142 if ( c == EOF ) set_fail();
147 istream& istream::operator>>(char* s)
150 if ( (c=eatw()) == EOF ) return *this;
155 c = sbuf -> examine();
156 } while (!isspace(c) && c != EOF) ;
168 istream::operator>>(unsigned short& x)
174 x = (unsigned short)l;
180 istream::operator>>(unsigned int& n)
183 if ( (x=eatw()) == EOF ) return *this;
191 } while (isdigit(x=sbuf->examine()));
203 istream::operator>>(int& x)
215 istream::operator>>(long& n)
219 if ( (x=eatw()) == EOF ) return *this;
228 x = sbuf -> examine();
240 } while (isdigit(x=sbuf->examine()));
251 /////////////////////
253 ostream::operator<<(void* a)
255 if ( fail() ) return *this;
262 ostream::operator<<(const char* str)
270 if (sbuf->put(*str++) == EOF) {
280 ostream::operator<<(char c)
282 if ( fail() ) return *this;
288 ostream::operator<<(int i)
296 ostream::operator<<(unsigned int l)
304 ostream::operator<<(long x)
306 if ( fail() ) return *this;
317 *p++ = '0' + char(x%10);
322 if (sbuf->put(*--p) == EOF) {
333 ostream::operator<< (ostream& (*f)(ostream&))
338 ostream& ostream::put(char c)
340 if ( fail() ) return *this;
345 ostream& ostream::flush()
347 if ( fail() ) return *this;
353 ostream::write(const char* s, int n)
355 for ( int i=0; i<n; i++ ) {
356 if ( sbuf->put(s[i]) == EOF )
362 ostream& endl(ostream& out)
367 istream::istream(streambuf* sb) : ios(sb)
372 ostream::ostream(streambuf* sb) : ios(sb)
377 iostream::iostream(streambuf* sb) : istream(sb), ostream(sb)