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

📄 isgetline.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 __isgetline_o = 0;#elsechar _N_ = 0;#endif#ifdef __cplusplus}#endif#include "vxWorks.h"/* This is part of libio/iostream, providing -*- C++ -*- input/output.Copyright (C) 1993 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. */#include <libioP.h>#include "iostream.h"#include <string.h>/* We replace new by new (nothrow) when exceptions aren't turned on */#ifndef _IO_THROW#include <new>#endifistream& istream::getline(char* buf, int len, char delim){  _gcount = 0;  if (len <= 0)    {      set(ios::failbit);      return *this;    }  int ch;  if (ipfx1())    {      streambuf *sb = rdbuf();      _gcount = _IO_getline(sb, buf, len - 1, delim, -1);      ch = sb->sbumpc();      if (ch == EOF)	set (_gcount == 0 ? (ios::failbit|ios::eofbit) : ios::eofbit);      else if (ch != (unsigned char) delim)	{	  set(ios::failbit);	  sb->sungetc(); // Leave delimiter unread.	}    }  else    ch = EOF;  buf[_gcount] = '\0';  if (ch == (unsigned char)delim)    _gcount++; // The delimiter is counted in the gcount().  return *this;}istream& istream::get(char* buf, int len, char delim){  _gcount = 0;  if (len <= 0)    {      set(ios::failbit);      return *this;    }  if (ipfx1())    {      streambuf *sbuf = rdbuf();      long count = _IO_getline(sbuf, buf, len - 1, delim, -1);      if (count == 0 && sbuf->sgetc() == EOF)	set(ios::failbit|ios::eofbit);      else	_gcount = count;    }  buf[_gcount] = '\0';  return *this;}// from Doug Schmidt#define CHUNK_SIZE 512/* Reads an arbitrarily long input line terminated by a user-specified   TERMINATOR.  Super-nifty trick using recursion avoids unnecessary calls   to NEW! */char *_sb_readline (streambuf *sb, long& total, char terminator) {    char buf[CHUNK_SIZE];    char *ptr;    int ch;        _IO_size_t count = _IO_getline(sb, buf, CHUNK_SIZE, terminator, -1);    ch = sb->sbumpc();    long old_total = total;    total += count;    if (ch != EOF && ch != terminator) {	total++; // Include ch in total.	ptr = _sb_readline(sb, total, terminator);	if (ptr) {	    memcpy(ptr + old_total, buf, count);	    ptr[old_total+count] = ch;	}	return ptr;    }        ptr = new char[total+1];    if (ptr != NULL) {	ptr[total] = '\0';	memcpy(ptr + total - count, buf, count);    }     return ptr;}/* Reads an arbitrarily long input line terminated by TERMINATOR.   This routine allocates its own memory, so the user should   only supply the address of a (char *). */istream& istream::gets(char **s, char delim /* = '\n' */){    if (ipfx1()) {	long size = 0;	streambuf *sb = rdbuf();	*s = _sb_readline (sb, size, delim);	_gcount = *s ? size : 0;	if (sb->_flags & _IO_EOF_SEEN) {	    set(ios::eofbit);	    if (_gcount == 0)		set(ios::failbit);	}    }    else {	_gcount = 0;	*s = NULL;    }    return *this;}

⌨️ 快捷键说明

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