⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 streambuf.cpp

📁 vxworks源码源码解读是学习vxworks的最佳途径
💻 CPP
字号:
/* This has been copied from the gnu source tree *//* Make all changes there, not here! */#ifdef __cplusplusextern "C" {#endif#ifndef _N_char __streambuf_o = 0;#elsechar _N_ = 0;#endif#ifdef __cplusplus}#endif#include "vxWorks.h"/* This is part of libio/iostream, providing -*- C++ -*- input/output.Copyright (C) 1991, 1992, 1993, 1995 Free Software FoundationThis file is part of the GNU IO Library.  This library is freesoftware; you can redistribute it and/or modify it under theterms of the GNU General Public License as published by theFree Software Foundation; either version 2, or (at your option)any later version.This library is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See theGNU General Public License for more details.You should have received a copy of the GNU General Public Licensealong with this library; see the file COPYING.  If not, write to the FreeSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.As a special exception, if you link this library with filescompiled with a GNU compiler to produce an executable, this does not causethe resulting executable to be covered by the GNU General Public License.This exception does not however invalidate any other reasons whythe executable file might be covered by the GNU General Public License. *//* Written by Per Bothner (bothner@cygnus.com). *//*  * This hack ensures that VxWorks contains a symbol called fd. Customers * often want to type * -> fd = 0 * at the Wind Shell. Because of the screwy way the Wind Shell * lexer looks up names in the symbol table this will give * a syntax error due to the conflict between fd and filebuf::fd - * unless `fd' is already in the symbol table. * Here we define fd as a `common' symbol so customers can * still use fd in their code. */int fd;#define _STREAM_COMPAT#ifdef __GNUG__#pragma implementation#endif#include "iostreamP.h"#include <string.h>#include <stdarg.h>#include <errno.h>#ifndef errnoextern int errno;#endif/* We replace new by new (nothrow) when exceptions aren't turned on */#ifndef _IO_THROW#include <new>#endifvoid streambuf::_un_link() { _IO_un_link(this); }void streambuf::_link_in() { _IO_link_in(this); }int streambuf::switch_to_get_mode(){ return _IO_switch_to_get_mode(this); }void streambuf::free_backup_area(){ _IO_free_backup_area(this); }#if 0int streambuf::switch_to_put_mode(){ return _IO_:switch_to_put_mode(this); }#endifint __overflow(streambuf* sb, int c){    return sb->overflow(c);}int streambuf::underflow(){ return EOF; }int streambuf::uflow(){ return _IO_default_uflow (this); }int streambuf::overflow(int /* = EOF */){ return EOF; }streamsize streambuf::xsputn(register const char* s, streamsize n){ return _IO_default_xsputn(this, s, n); }streamsize streambuf::xsgetn(char* s, streamsize n){ return _IO_default_xsgetn(this, s, n); }int streambuf::ignore(int n){    register int more = n;    for (;;) {	int count = _IO_read_end - _IO_read_ptr; // Data available.	if (count > 0) {	    if (count > more)		count = more;	    _IO_read_ptr += count;	    more -= count;	}	if (more == 0 || __underflow(this) == EOF)	    break;    }    return n - more;}int streambuf::sync(){  return 0;}int streambuf::pbackfail(int c){  return _IO_default_pbackfail(this, c);}streambuf* streambuf::setbuf(char* p, int len){    if (sync() == EOF)	return NULL;    if (p == NULL || len == 0) {	unbuffered(1);	setb(_shortbuf, _shortbuf+1, 0);    }    else {	unbuffered(0);	setb(p, p+len, 0);    }    setp(0, 0);    setg(0, 0, 0);    return this;}streampos streambuf::seekpos(streampos pos, int mode){    return seekoff(pos, ios::beg, mode);}streampos streambuf::sseekpos(streampos pos, int mode){  return _IO_seekpos (this, pos, mode);}void streambuf::setb(char* b, char* eb, int a){ _IO_setb(this, b, eb, a); }int streambuf::doallocate() { return _IO_default_doallocate(this); }void streambuf::doallocbuf() { _IO_doallocbuf(this); }#if !_IO_UNIFIED_JUMPTABLES/* The following are jump table entries that just call the virtual method */static int _IO_sb_overflow(_IO_FILE *fp, int c){ return ((streambuf*)fp)->overflow(c); }static int _IO_sb_underflow(_IO_FILE *fp){ return ((streambuf*)fp)->underflow(); }static _IO_size_t _IO_sb_xsputn(_IO_FILE *fp, const void *s, _IO_size_t n){ return ((streambuf*)fp)->xsputn((const char*)s, n); }static _IO_size_t _IO_sb_xsgetn(_IO_FILE *fp, void *s, _IO_size_t n){ return ((streambuf*)fp)->xsgetn((char*)s, n); }static int _IO_sb_close(_IO_FILE *fp){ return ((streambuf*)fp)->sys_close(); }static int _IO_sb_stat(_IO_FILE *fp, void *b){ return ((streambuf*)fp)->sys_stat(b); }static int _IO_sb_doallocate(_IO_FILE *fp){ return ((streambuf*)fp)->doallocate(); }static _IO_pos_t _IO_sb_seekoff(_IO_FILE *fp, _IO_off_t pos, int dir, int mode){  return ((streambuf*)fp)->seekoff(pos, (ios::seek_dir)dir, mode);}static _IO_pos_t _IO_sb_seekpos(_IO_FILE *fp, _IO_pos_t pos, int mode){  return ((streambuf*)fp)->seekpos(pos, mode);}static int _IO_sb_pbackfail(_IO_FILE *fp, int ch){ return ((streambuf*)fp)->pbackfail(ch); }static void _IO_sb_finish(_IO_FILE *fp, int){ ((streambuf*)fp)->~streambuf(); }static _IO_ssize_t _IO_sb_read(_IO_FILE *fp, void *buf, _IO_ssize_t n){ return ((streambuf*)fp)->sys_read((char*)buf, n); }static _IO_ssize_t _IO_sb_write(_IO_FILE *fp, const void *buf, _IO_ssize_t n){ return ((streambuf*)fp)->sys_write((const char*)buf, n); }static int _IO_sb_sync(_IO_FILE *fp){ return ((streambuf*)fp)->sync(); }static _IO_pos_t _IO_sb_seek(_IO_FILE *fp, _IO_off_t off, int dir){ return ((streambuf*)fp)->sys_seek(off, (_seek_dir)dir); }static _IO_FILE* _IO_sb_setbuf(_IO_FILE *fp, char *buf, _IO_ssize_t n){ return ((streambuf*)fp)->setbuf(buf, n); }/* This callbacks in this jumptable just call the corresponding   virtual function, so that C functions can access (potentially user-defined)   streambuf-derived objects.   Contrast the builtinbuf class, which does the converse:  Allow   C++ virtual calls to to be used on _IO_FILE objects that are builtin   (or defined by C code). */struct _IO_jump_t _IO_streambuf_jumps = {  JUMP_INIT_DUMMY,  JUMP_INIT(finish, _IO_sb_finish),  JUMP_INIT(overflow, _IO_sb_overflow),  JUMP_INIT(underflow, _IO_sb_underflow),  JUMP_INIT(uflow, _IO_default_uflow),  JUMP_INIT(pbackfail, _IO_sb_pbackfail),  JUMP_INIT(xsputn, _IO_sb_xsputn),  JUMP_INIT(xsgetn, _IO_sb_xsgetn),  JUMP_INIT(seekoff, _IO_sb_seekoff),  JUMP_INIT(seekpos, _IO_sb_seekpos),  JUMP_INIT(setbuf, _IO_sb_setbuf),  JUMP_INIT(sync, _IO_sb_sync),  JUMP_INIT(doallocate, _IO_sb_doallocate),  JUMP_INIT(read, _IO_sb_read),  JUMP_INIT(write, _IO_sb_write),  JUMP_INIT(seek, _IO_sb_seek),  JUMP_INIT(close, _IO_sb_close),  JUMP_INIT(stat, _IO_sb_stat)};#endifstreambuf::streambuf(int flags){#ifdef _IO_MTSAFE_IO  _lock = new _IO_lock_t;#endif  _IO_init(this, flags);#if !_IO_UNIFIED_JUMPTABLES  _jumps = &_IO_streambuf_jumps;#endif}streambuf::~streambuf(){  _IO_default_finish(this,0);#ifdef _IO_MTSAFE_IO  if (this != _IO_stdin && this != _IO_stdout && this != _IO_stderr)    delete _lock;#endif}streamposstreambuf::seekoff(streamoff, _seek_dir, int /*=ios::in|ios::out*/){    return EOF;}streamposstreambuf::sseekoff(streamoff o , _seek_dir d, int m /*=ios::in|ios::out*/){  return _IO_seekoff (this, o, d, m);}int streambuf::sputbackc(char c){  return _IO_sputbackc(this, c);}int streambuf::sungetc(){  return _IO_sungetc(this);}#if 0 /* Work in progress */void streambuf::collumn(int c){    if (c == -1)	_collumn = -1;    else	_collumn = c - (_IO_write_ptr - _IO_write_base);}#endifint streambuf::get_column(){    if (_cur_column) 	return _IO_adjust_column(_cur_column - 1, pbase(), pptr() - pbase());    return -1;}int streambuf::set_column(int i){    _cur_column = i+1;    return 0;}int streambuf::flush_all() { return _IO_flush_all (); }void streambuf::flush_all_linebuffered(){ _IO_flush_all_linebuffered(); }int streambuf::sys_stat(void *){#ifdef EIO  errno = EIO;#endif  return -1;}streamsize streambuf::sys_read(char* /*buf*/, streamsize /*size*/){  return 0;}streamsize streambuf::sys_write(const char* /*buf*/, streamsize /*size*/){  return 0;}streampos streambuf::sys_seek(streamoff, _seek_dir){  return EOF;}int streambuf::sys_close() { return 0; /* Suceess; do nothing */ }streammarker::streammarker(streambuf *sb){  _IO_init_marker(this, sb);}streammarker::~streammarker(){  _IO_remove_marker(this);}#define BAD_DELTA EOFint streammarker::delta(streammarker& other_mark){  return _IO_marker_difference(this, &other_mark);}int streammarker::delta(){  return _IO_marker_delta(this);}int streambuf::seekmark(streammarker& mark, int delta /* = 0 */){  return _IO_seekmark(this, &mark, delta);}void streambuf::unsave_markers(){  _IO_unsave_markers(this);}int ios::readable() { return !(rdbuf()->_flags & _IO_NO_READS); }int ios::writable() { return !(rdbuf()->_flags & _IO_NO_WRITES); }int ios::is_open() { return rdbuf()			 && (rdbuf()->_flags & _IO_NO_READS+_IO_NO_WRITES)			     != _IO_NO_READS+_IO_NO_WRITES; }#if defined(linux)#define IO_CLEANUP#endif#ifdef IO_CLEANUP  IO_CLEANUP#elsestruct __io_defs {    ~__io_defs() { _IO_cleanup (); }};   __io_defs io_defs__;#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -