|
|
1.1 ! root 1: /*ident "@(#)ctrans:lib/stream/stdiobuf.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: stdiobuf.c: ! 12: ! 13: *****************************************************************************/ ! 14: ! 15: ! 16: #include <iostream.h> ! 17: #include <stdiostream.h> ! 18: ! 19: int stdiobuf::overflow(int c) ! 20: { ! 21: if ( fp == 0 || c==EOF) return EOF ; ! 22: if ( last_op == ios::in ) { ! 23: if ( egptr()!=gptr() ) ungetc(*gptr(),fp) ; ! 24: // stdio requires seeks between reads and writes ! 25: fseek(fp,0,ios::cur) ; ! 26: setg(0,0,0) ; ! 27: } ! 28: last_op = ios::out ; ! 29: ! 30: return putc(c,fp) ; ! 31: } ! 32: ! 33: int stdiobuf::underflow() { ! 34: if ( fp == 0 ) return EOF ; ! 35: if ( last_op == ios::out ) { ! 36: fseek(fp,0,0) ; ! 37: } ! 38: if ( feof(fp) ) return EOF ; ! 39: int c = getc(fp) ; ! 40: if ( c == EOF ) return EOF ; ! 41: setg(buf,buf,buf+1) ; ! 42: buf[0] = c ; ! 43: return c ; ! 44: } ! 45: ! 46: int stdiobuf::pbackfail(int c) ! 47: { ! 48: return ungetc(c,fp) ; ! 49: } ! 50: ! 51: int stdiobuf::sync() ! 52: { ! 53: if ( last_op==ios::out ) fflush(fp) ; ! 54: else if ( last_op==ios::in && gptr()!=egptr() ) { ! 55: ungetc(*gptr(),fp) ; ! 56: setg(0,0,0) ; ! 57: } ! 58: return fseek(fp,0,ios::cur) ; ! 59: } ! 60: ! 61: streampos stdiobuf::seekoff(streamoff p,ios::seek_dir d,int) ! 62: { ! 63: ! 64: if ( gptr()!=egptr() ) ungetc(*gptr(),fp) ; ! 65: setg(0,0,0) ; ! 66: return fseek(fp,p,d) ; ! 67: } ! 68: ! 69: stdiobuf::stdiobuf(FILE* f) : ! 70: fp(f) ! 71: { ! 72: setbuf((char*)0,0) ; ! 73: } ! 74: ! 75: stdiobuf::~stdiobuf() ! 76: { ! 77: if (fp) fflush(fp) ; ! 78: } ! 79: ! 80: stdiostream::stdiostream(FILE* f) : buf(f) ! 81: { ! 82: init(&buf) ; ! 83: } ! 84: ! 85: stdiostream::~stdiostream() { } ! 86: ! 87: stdiobuf* stdiostream::rdbuf() { return &buf ; }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.