Ejemplo n.º 1
0
strstreambuf::pos_type
strstreambuf::seekoff(off_type off, ios_base::seekdir dir, ios_base::openmode which)
{
  if (dir == ios_base::cur && (which & (ios_base::in | ios_base::out)) == (ios_base::in | ios_base::out)
      || (which & (ios_base::in | ios_base::out)) == 0)
    return pos_type(-1);

  off_type newoff = 0;
  if (dir == ios_base::cur)
    newoff = ((which & ios_base::in) != 0? gptr(): pptr()) - eback();
  else
    newoff = (epptr() == 0? egptr(): epptr()) - eback();

  if (newoff + off < gptr() - eback() || newoff + off >= epptr() - eback())
    return pos_type(-1);
  
  if (which & ios_base::in)
    if (gptr() == 0)
      return pos_type(-1);
    else
      setg(eback(), eback() + newoff + off, egptr());

  if (which & ios_base::out)
    if (pptr() == 0)
      return pos_type(-1);
    else
      setp(eback() + newoff + off, epptr());

  return newoff + off;
}
Ejemplo n.º 2
0
streamsize CCompressionStreambuf::xsputn(const CT_CHAR_TYPE* buf,
                                         streamsize count)
{
    // Check processor's state
    if ( !IsStreamProcessorOkay(CCompressionStream::eWrite) ) {
        return CT_EOF;
    }
    if ( m_Writer->m_State == CSP::eFinalize ) {
        return CT_EOF;
    }
    // Check parameters
    if ( !buf  ||  count <= 0 ) {
        return 0;
    }
    // The number of chars copied
    streamsize done = 0;

    // Loop until no data is left
    while ( done < count ) {
        // Get the number of chars to write in this iteration
        // (we've got one more char than epptr thinks)
        size_t block_size = min(size_t(count-done), size_t(epptr()-pptr()+1));
        // Write them
        memcpy(pptr(), buf + done, block_size);
        // Update the write pointer
        pbump((int)block_size);
        // Process block if necessary
        if ( pptr() >= epptr()  &&  !ProcessStreamWrite() ) {
            break;
        }
        done += block_size;
    }
    return done;
};
Ejemplo n.º 3
0
strstreambuf::int_type
strstreambuf::overflow (int_type c)
{
  if (c == char_traits<char>::eof())
    return ' ';

  if (pptr() == epptr())
    {
      if (_CS_m_dynamic == 0 || _CS_m_frozen == 1)
	return char_traits<char>::eof();

      streamsize n = epptr() - eback();
      char* tmp = _CS_m_alloc == 0
	? new char[n + _CS_m_chunk_size]
	: static_cast<char*>(_CS_m_alloc(n + _CS_m_chunk_size));
      char_traits<char>::copy(tmp, eback(), n);
      char* del = eback();
      setg(tmp, tmp + (gptr() - del), tmp + (egptr() - del));
      setp(tmp + (pptr() - del), tmp + n + _CS_m_chunk_size);
      if (_CS_m_allocated != 0)
	_CS_m_free == 0? delete[] del: _CS_m_free(del);

      _CS_m_allocated = 1;
    }

  *pptr() = static_cast<unsigned char>(c);
  pbump(1);
  return c;
}
strstreambuf::pos_type
strstreambuf::seekpos(pos_type __sp, ios_base::openmode __which)
{
    off_type __p(-1);
    bool pos_in = (__which & ios::in) != 0;
    bool pos_out = (__which & ios::out) != 0;
    if (pos_in || pos_out)
    {
        if (!((pos_in && gptr() == nullptr) || (pos_out && pptr() == nullptr)))
        {
            off_type newoff = __sp;
            char* seekhigh = epptr() ? epptr() : egptr();
            if (0 <= newoff && newoff <= seekhigh - eback())
            {
                char* newpos = eback() + newoff;
                if (pos_in)
                    setg(eback(), newpos, _VSTD::max(newpos, egptr()));
                if (pos_out)
                {
                    // min(pbase, newpos), newpos, epptr()
                    off_type temp = epptr() - newpos;
                    setp(min(pbase(), newpos), epptr());
                    pbump(static_cast<int>((epptr() - pbase()) - temp));
                }
                __p = newoff;
            }
        }
    }
    return pos_type(__p);
}
int strstreambuf::overflow(int c)
{
/*
- if no room and not dynamic, give error
- if no room and dynamic, allocate (1 more or min) and store
- if and when the buffer has room, store c if not EOF
*/
    int temp;
    if (pptr() >= epptr())
        {
        if (!x_dynamic)
            return EOF;

        if (strstreambuf::doallocate()==EOF)
            return EOF;

        if (!epptr())   // init if first time through
            {
            setp(base() + (egptr() - eback()),ebuf());
            }
        else
            {
            temp = pptr()-pbase();
            setp(pbase(),ebuf());
            pbump(temp);
            }
        }

    if (c!=EOF)
        {
        *pptr() = (char)c;
        pbump(1);
        }
    return(1);
}
Ejemplo n.º 6
0
 /**
  * Appends @c n characters from the start of the output sequence to the input
  * sequence. The beginning of the output sequence is advanced by @c n
  * characters.
  *
  * Requires a preceding call <tt>prepare(x)</tt> where <tt>x >= n</tt>, and
  * no intervening operations that modify the input or output sequence.
  *
  * @throws std::length_error If @c n is greater than the size of the output
  * sequence.
  */
 void commit(std::size_t n)
 {
   if (pptr() + n > epptr())
     n = epptr() - pptr();
   pbump(static_cast<int>(n));
   setg(eback(), gptr(), pptr());
 }
strstreambuf::pos_type
strstreambuf::seekoff(off_type __off, ios_base::seekdir __way, ios_base::openmode __which)
{
    off_type __p(-1);
    bool pos_in = (__which & ios::in) != 0;
    bool pos_out = (__which & ios::out) != 0;
    bool legal = false;
    switch (__way)
    {
    case ios::beg:
    case ios::end:
        if (pos_in || pos_out)
            legal = true;
        break;
    case ios::cur:
        if (pos_in != pos_out)
            legal = true;
        break;
    }
    if (pos_in && gptr() == nullptr)
        legal = false;
    if (pos_out && pptr() == nullptr)
        legal = false;
    if (legal)
    {
        off_type newoff;
        char* seekhigh = epptr() ? epptr() : egptr();
        switch (__way)
        {
        case ios::beg:
            newoff = 0;
            break;
        case ios::cur:
            newoff = (pos_in ? gptr() : pptr()) - eback();
            break;
        case ios::end:
            newoff = seekhigh - eback();
            break;
        default:
            return pos_type(off_type(-1));
        }
        newoff += __off;
        if (0 <= newoff && newoff <= seekhigh - eback())
        {
            char* newpos = eback() + newoff;
            if (pos_in)
                setg(eback(), newpos, _VSTD::max(newpos, egptr()));
            if (pos_out)
            {
                // min(pbase, newpos), newpos, epptr()
                __off = epptr() - newpos;
                setp(min(pbase(), newpos), epptr());
                pbump(static_cast<int>((epptr() - pbase()) - __off));
            }
            __p = newoff;
        }
    }
    return pos_type(__p);
}
Ejemplo n.º 8
0
int strstreambuf::overflow(int meta)
	{	// try to extend write area
	if (meta == EOF)
		return (0);	// nothing to write
	else if (pptr() != 0 && pptr() < epptr())
		return ((unsigned char)(*_Pninc() = meta));	// room in buffer
	else if (!(_Strmode & _Dynamic)
		|| _Strmode & (_Constant | _Frozen))
		return (EOF);	// can't extend
	else
		{	// okay to extend
		int oldsize = gptr() == 0 ? 0 : epptr() - eback();
		int newsize = oldsize;
		int inc = newsize / 2 < _Minsize
			? _Minsize : newsize / 2;	// grow by 50 per cent if possible
		_Minsize = _MINSIZE;	// back to default for future growth
		char *ptr = 0;

		while (0 < inc && INT_MAX - inc < newsize)
			inc /= 2;	// reduce growth increment if too big
		if (0 < inc)
			{	// room to grow, increase size
			newsize += inc;
			ptr = _Palloc != 0 ? (char *)(*_Palloc)(newsize)
				: _NEW_CRT char[newsize];
			}
		if (ptr == 0)
			return (EOF);	// couldn't grow, return failure

		if (0 < oldsize)
			memcpy(ptr, eback(), oldsize);	// copy existing buffer
		if (!(_Strmode & _Allocated))
			;	// no buffer to free
		else if (_Pfree != 0)
			(*_Pfree)(eback());	// free with function call
		else
			_DELETE_CRT_VEC(eback());	// free by deleting array

		_Strmode |= _Allocated;
		if (oldsize == 0)
			{	// set up new buffer
			_Seekhigh = ptr;
			setp(ptr, ptr + newsize);
			setg(ptr, ptr, ptr);
			}
		else
			{	// revise old pointers
			_Seekhigh = _Seekhigh - eback() + ptr;
			setp(pbase() - eback() + ptr, pptr() - eback() + ptr,
				ptr + newsize);
			setg(ptr, gptr() - eback() + ptr, pptr() + 1);
			}

		return ((unsigned char)(*_Pninc() = meta));
		}
Ejemplo n.º 9
0
std::ios::pos_type
Charbuf::seekoff(std::ios::off_type off, std::ios_base::seekdir dir,
    std::ios_base::openmode which)
{
    std::ios::pos_type pos;
    char *cpos = nullptr;
    if (which & std::ios_base::in)
    {
        switch (dir)
        {
        case std::ios::beg:
            cpos = eback() + off - m_bufOffset;
            break;
        case std::ios::cur:
            cpos = gptr() + off;
            break;
        case std::ios::end:
            cpos = egptr() - off;
            break;
        default:
            break;  // Should never happen.
        }
        if (cpos < eback() || cpos > egptr())
            return -1;
        setg(eback(), cpos, egptr());
        pos = cpos - eback();
    }
    if (which & std::ios_base::out)
    {
        switch (dir)
        {
        case std::ios::beg:
            cpos = m_buf + off - m_bufOffset;
            break;
        case std::ios::cur:
            cpos = pptr() + off;
            break;
        case std::ios::end:
            cpos = egptr() - off;
            break;
        default:
            break;  // Should never happen.
        }
        if (cpos < m_buf || cpos > epptr())
            return -1;
        setp(cpos, epptr());
        pos = cpos - m_buf;
    }
    return pos;
}
Ejemplo n.º 10
0
  streampos strstreambuf::seekoff( streamoff offset,
                                   ios::seekdir direction,
                                   int mode ) {

    streampos  newpos;
    char      *endget;
    char      *pos;

    mode &= (ios::in | ios::out);
    if( (mode == 0) ||
      ( (direction==ios::cur) && (mode == (ios::in | ios::out)) ) ) {
        return( EOF );
    }

    __lock_it( __b_lock );

    // Move the get pointer:
    if( mode & ios::in ) {
        endget = pptr();
        if( endget == NULL || endget < egptr() ) {
            endget = egptr();
        }
        newpos = __get_position( offset, direction, eback(), gptr(), egptr(), endget );
        if( newpos != EOF ) {

            // If the seek went beyond the end of the get area, extend the
            // get area to include the characters in the put area.
            pos = eback() + newpos;
            if( pos > egptr() ) {
                setg( eback(), pos, epptr() );
            } else {
                setg( eback(), pos, egptr() );
            }
        }
    }

    if( mode & ios::out ) {
        // Move the put pointer:
        newpos = __get_position( offset, direction, pbase(), pptr(), epptr(), epptr() );
        if( newpos != EOF ) {
            setp( pbase(), epptr() );
            pbump( newpos );
            if( newpos > __minbuf_size ) {
                __minbuf_size = (int)newpos;
            }
        }
    }
    return( newpos );
  }
Ejemplo n.º 11
0
_STLP_EXP_DECLSPEC strstreambuf::int_type strstreambuf::overflow(int_type c) {
  if (c == traits_type::eof())
    return traits_type::not_eof(c);
#ifdef __SYMBIAN32__
  if (pptr() != 0 && pptr() < epptr())
  {
    *pptr() = c;
    pbump(1);
    return c;
  }
  if (!_M_dynamic || _M_constant || _M_frozen)
  	return (EOF);	// can't extend
#endif
  // Try to expand the buffer.
  if (pptr() == epptr() && _M_dynamic && !_M_frozen && !_M_constant) {
    ptrdiff_t old_size = epptr() - pbase();
    ptrdiff_t new_size = (max)(2 * old_size, ptrdiff_t(1));

    char* buf = _M_alloc(new_size);
    if (buf) {
      memcpy(buf, pbase(), old_size);

      char* old_buffer = pbase();
      bool reposition_get = false;
      ptrdiff_t old_get_offset;
      if (gptr() != 0) {
        reposition_get = true;
        old_get_offset = gptr() - eback();
      }

      setp(buf, buf + new_size);
      pbump((int)old_size);

      if (reposition_get) 
        setg(buf, buf + old_get_offset, buf + (max)(old_get_offset, old_size));

      _M_free(old_buffer);
    }
  }

  if (pptr() != epptr()) {
    *pptr() = c;
    pbump(1);
    return c;
  }
  else
    return traits_type::eof();
}
Ejemplo n.º 12
0
void sha1buf::update_sha1(uint32_t &H0, uint32_t &H1, uint32_t &H2, uint32_t &H3, uint32_t &H4)
{
	uint64_t bits(len);
	uint32_t *words = (uint32_t *) buf;
	char *ptr = pptr(), *end = epptr();

	bits += (ptr - pbase()) * 8;

	std::ptrdiff_t pad = end + 1 - ptr;
	if (pad) {
		*ptr = '\x80';

		if (pad >= 9)
			end -= 8;

		while (ptr++ < end)
			*ptr = '\0';

		if (pad < 9) {
			_update_sha1(H0, H1, H2, H3, H4, words);
			words = new uint32_t[16]();
		}

		words[15] = _BE(bits);
		words[14] = _BE(((uint32_t *) &bits)[1]);
	}

	_update_sha1(H0, H1, H2, H3, H4, words);
}
Ejemplo n.º 13
0
stringbuf::int_type stringbuf::overflow(int_type __char)
{
    if (__char == EOF) return 0;     // __char is EOF, so we don't have to do anything

    if (__M_mode & ios_base::out) 
    {
        if (pptr() < epptr())    // just put back in any case
        { 
            __M_str.push_back(static_cast<char_type>(__char));
            pbump(1);
        }
        else if (__M_mode & ios_base::in) 
        {
            ptrdiff_t __offset = gptr() - eback();
            __M_str.push_back(static_cast<char_type>(__char));
            char_type* __data_ptr = __M_str.begin();
            setg(__data_ptr, __data_ptr + __offset, __M_str.end());
            setp(__data_ptr, __M_str.end());
            pbump(static_cast<int>(__M_str.size()));
        }
        else 
        {
            __M_str.push_back(static_cast<char_type>(__char));
            setp(__M_str.begin(), __M_str.end());
            pbump(static_cast<int>(__M_str.size()));
        }
        return __char;
    }
    return EOF;     // Overflow always fails if it's read-only
}
Ejemplo n.º 14
0
int _ALControlStream::overflow( int ch )
{
    if ( !base() ) {
        if ( allocate() == EOF )
            return EOF;
        setg( 0, 0, 0 );
    } else {
        if ( out_waiting() ) {
            if ( sync() == EOF )
                return EOF;
        }
    }
    int bl = blen();
    setp( base(), base() + bl - 2 );
    if ( pptr() < epptr() ) {
        *pptr() = (char) ch;
        pbump( 1 );
    } else {
        *pptr() = (char ) ch;
        pbump( 1 );
        *pptr() = '\0';
        pbump( 1 );
        SendMessage( hWindow,
                     EM_REPLACESEL,
                     0,
                     (LPARAM) ( (LPSTR) pbase() ) );
    }
    return 0;
}
_CRTIMP2 streampos strstreambuf::seekpos(streampos sp,
		ios::openmode which)
	{	// seek to memorized position
	streamoff off = (streamoff)sp;
	if (pptr() != 0 && _Seekhigh < pptr())
		_Seekhigh = pptr();
	if (off == _BADOFF)
		;
	else if (which & ios::in && gptr() != 0)
		{	// set input (and maybe output) pointer
		if (0 <= off && off <= _Seekhigh - eback())
			{	// set valid offset
			gbump(eback() - gptr() + off);
			if (which & ios::out && pptr() != 0)
				setp(pbase(), gptr(), epptr());
			}
		else
			off = _BADOFF;
		}
	else if (which & ios::out && pptr() != 0)
		{	// set output pointer
		if (0 <= off && off <= _Seekhigh - eback())
			pbump(eback() - pptr() + off);
		else
			off = _BADOFF;
		}
	else	// nothing to set
		off = _BADOFF;
	return (streampos(off));
	}
Ejemplo n.º 16
0
std::streamsize LogBuf::xsputn(const Char8 *buffer, std::streamsize size)
{
    if(size > 0)
    {
        if(!pptr())
            return 0;

        std::streamsize s = epptr() - pptr();

        if(s >= size)
        {
            // Put it into the write buffer
            memcpy(pptr(), buffer, size);
            pbump(size);
        }
        else
        {
            // Flush write buffer
            s = pptr() - pbase();

            if (s > 0)
            {
                write(pbase(), s);
                pbump(-s);
            }

            // Write data
            write(buffer, size);
        }
    }

    return size;
}
Ejemplo n.º 17
0
int rpcbuf::overflow(int c) {
    if (!_opened || allocate() == EOF) {
	return EOF;
    }

    if (c == EOF) {
	finish_request();
    }

    if (rptr() == pbase() && pptr() >= epptr() && !expand_p()) {
	error("rpcbuf::overflow: out of memory");
	return EOF;
    }

    int nwrite = (rptr() >= pbase()) ? rptr() - pbase() : out_waiting();
    int count = 0;
    while (count < nwrite) {
	int nsent = write(_fd, pbase() + count, nwrite - count);
	if (nsent < 0) {
	    sys_error("rpcbuf::overflow: write");
	    return EOF;
	}
	count += nsent;
    }
    if (rptr() > pbase()) {
	Memory::copy(rptr(), pbase(), pptr() - rptr());
	rbump(-nwrite);
    }
    pbump(-nwrite);

    if (c != EOF) {
	sputc(c);
    }
    return zapeof(c);
}
Ejemplo n.º 18
0
 int sync() {
     if( pbase() != pptr() ) {
         m_writer( std::string( pbase(), static_cast<std::string::size_type>( pptr() - pbase() ) ) );
         setp( pbase(), epptr() );
     }
     return 0;
 }
Ejemplo n.º 19
0
_STLP_EXP_DECLSPEC void strstreambuf::freeze(bool frozenflag)
{
#ifdef __SYMBIAN32__
  if (_M_dynamic)
  {
    //
	if (frozenflag && !_M_frozen)
		{	// disable writing
		_M_frozen = frozenflag;
		_pfrozenendsave = epptr();
        _pgetfrozenendsave = pptr();
		setp(pbase(), eback());
		}
	else if (!frozenflag && _M_frozen)
		{	// re-enable writing
		_M_frozen = frozenflag;
		if(_pfrozenendsave != NULL)
		    {
		    setp(pbase(), _pfrozenendsave);
		    setg(pbase(),  pbase(), _pgetfrozenendsave);
		    }
		}
  }
#else
  if (_M_dynamic)
    _M_frozen = frozenflag;
#endif
}
Ejemplo n.º 20
0
 std::streamsize xsputn(const char_type * s, std::streamsize n)
 {
     const char_type * end = s + n;
     size_t c = std::min<size_t>(end - s, epptr() - pptr());
     memcpy(pptr(), s, c);
     pbump(static_cast<int>(c));
     s += c;
     if(s != end)
     {
         size_t c;
         cur_->next = new Buffer;
         cur_ = cur_->next;
         for(;;)
         {
             c = std::min<size_t>(end - s, bufferSize);
             memcpy(&cur_->data[0], s, c);
             s += c;
             if(s == end)
                 break;
             cur_->next = new Buffer;
             cur_ = cur_->next;
         }
         char * begin = &cur_->data[0];
         std::streambuf::setp(begin + c, begin + bufferSize);
     }
     return n;
 }
Ejemplo n.º 21
0
std::streamsize SimpleStreamBuf::xsputn(const char* s, std::streamsize n)
{
    std::streamsize writeCount = 0;
    while(writeCount < n)
    {
        char* current_pptr = pptr();
        char* current_epptr = epptr();

        if (current_pptr < current_epptr)
        {
            std::size_t copySize = (std::min)(static_cast< std::size_t >(n - writeCount),
                                              static_cast< std::size_t >(current_epptr - current_pptr));

            std::memcpy(current_pptr, s + writeCount, copySize);
            writeCount += copySize;
            setp(current_pptr + copySize, current_epptr);
            setg(m_buffer, gptr(), pptr());
        }
        else if (overflow(std::char_traits< char >::to_int_type(*(s + writeCount))) != std::char_traits<char>::eof())
        {
            writeCount++;
        }
        else
        {
            return writeCount;
        }
    }

    return writeCount;
}
Ejemplo n.º 22
0
ostream &
SMKStrStreambuf::dumpInfo(
  ostream &	dest,
  const char *  prefix,
  bool		showVer
  )
{
  if( showVer )
    dest << SMKStrStreambuf::getClassName() << ":\n"
	 << SMKStrStreambuf::getVersion() << '\n';

  dest << prefix << "length:  " << plen() << '\n'
#if defined( SMK_HAVE_STRBUF_BASE )
       << prefix << "base():  " << (void *) base() << '\n'
#endif
#if defined( SMK_HAVE_STRBUF_EBUF )
       << prefix << "ebuf():  " << (void *) ebuf() << '\n'
#endif
       << prefix << "pbase(): " << (void *) pbase() << '\n'
       << prefix << "pptr():  " << (void *) pptr() << '\n'
       << prefix << "epptr(): " << (void *) epptr() << '\n'
       << prefix << "eback(): " << (void *) eback() << '\n'
       << prefix << "gptr():  " << (void *) gptr() << '\n'
       << prefix << "egptr(): " << (void *) egptr() << '\n'
       << prefix << "n - b:   " << pptr() - pbase() << '\n'
       << prefix << "string:  '" << (void *)cstr() << "'\n"
       << prefix << "pbase(): " << (void *) pbase() << '\n'
       << prefix << "pptr():  " << (void *) pptr() << '\n'
       << prefix << "length:  " << plen() << '\n'
       << prefix << "size:    " << psize() << '\n'
    ;

  return( dest );
}
int strstreambuf::doallocate()
{
    char * bptr;
    int size;
    size = __max(x_bufmin,blen() + __max(x_bufmin,1));
    long offset = 0;

    if (x_alloc)
        {
        bptr = (char*)(*x_alloc)(size);
        }
    else
        {
        bptr = _new_crt char[size];
        }
    if (!bptr)
        return EOF;

    if (blen())
        {
        memcpy(bptr, base(), blen());
        offset = bptr - base(); // amount to adjust pointers by
        }
    if (x_free)
        {
        (*x_free)(base());
        }
    else
        {
        delete base();
        }
    setb(bptr,bptr+size,0);     // we handle deallocation

    // adjust get/put pointers too, if necessary
    if (offset)
        if (egptr())
            {
            setg(eback()+offset,gptr()+offset,egptr()+offset);
            }
        if (epptr())
            {
            size = pptr() - pbase();
            setp(pbase()+offset,epptr()+offset);
            pbump(size);
        }
    return(1);
}
Ejemplo n.º 24
0
streamsize mem_streambuf::xsputn( char_type const *buf, streamsize size ) {
  streamsize const remaining = epptr() - pptr();
  if ( size > remaining )
    size = remaining;
  ::memcpy( pptr(), buf, static_cast<size_t>( size ) );
  pbump( static_cast<int>(size) );
  return size;
}
Ejemplo n.º 25
0
		virtual int_type overflow(int_type ch)
		{
			if(ch == traits_type::eof()) return traits_type::eof();
			*epptr() = (char_type)L'\0';
			sync();
			sputc(ch);
			return traits_type::not_eof(ch);
		}
int HTTPChunkedStreamBuf::overflow(int c)
{
	sync();
	if (c != EOF && (pptr() < epptr())) { // guard against recursion
		sputc(c);
	}
	return 0L;  // return 0 if successful
}
Ejemplo n.º 27
0
        std::streamsize xsputn (
            const char* s,
            std::streamsize num
        )
        {
            // Add a sanity check here 
            DLIB_ASSERT(num >= 0,
                "\tstd::streamsize filestreambuf::xsputn"
                << "\n\tThe number of bytes to write can't be negative"
                << "\n\tnum:  " << num 
                << "\n\tthis: " << this
            );

            std::streamsize space_left = static_cast<std::streamsize>(epptr()-pptr());
            if (num <= space_left)
            {
                std::memcpy(pptr(),s,static_cast<size_t>(num));
                pbump(static_cast<int>(num));
                return num;
            }
            else
            {
                std::memcpy(pptr(),s,static_cast<size_t>(space_left));
                s += space_left;
                pbump(space_left);
                std::streamsize num_left = num - space_left;

                if (flush_out_buffer() == EOF)
                {
                    // the write was not successful so return that 0 bytes were written
                    return 0;
                }

                if (num_left < out_buffer_size)
                {
                    std::memcpy(pptr(),s,static_cast<size_t>(num_left));
                    pbump(num_left);
                    return num;
                }
                else
                {
                    while(num_left != 0)
                    {
                        if(write_echoing_select(fd, fd_printf))
                            return EOF;
                        int status = write(fd,s,num_left);
                        if (status < 0)
                        {
                            // the write was not successful so return that 0 bytes were written
                            return 0;
                        } 
                        num_left -= status;
                        s += status;
                    }
                    return num;
                }
            }
        }
Ejemplo n.º 28
0
streamsize stringbuf::_M_xsputnc(char_type __char, streamsize __count) 
{
    if (((__M_mode & ios_base::out) == 0) || (__count <= 0)) return 0;

    streamsize __nwritten = 0;

    // If the put pointer is somewhere in the middle of the string, then overwrite instead of append.
    if (pbase() == __M_str.begin()) 
    {
        ptrdiff_t __avail = __M_str.end() - pptr();
        if (__avail >= __count) 
        {
            VOS_memset_s(pptr(), epptr() - pptr(), __char, static_cast<size_t>(__count));
            pbump(static_cast<int>(__count));
            return __count;
        }
        else 
        {
            VOS_memset_s(pptr(), epptr() - pptr(), __char, __avail);
            __nwritten += __avail;
            __count -= __avail;
        }
    }

    // At this point we know we're appending.
    size_t __app_size = static_cast<size_t>(__count);
    char_type* __data_ptr;
    if (__M_mode & ios_base::in) 
    {
        ptrdiff_t __get_offset = gptr() - eback();
        __M_str.append(__app_size, __char);
        __data_ptr = __M_str.begin();
        setg(__data_ptr, __data_ptr + __get_offset, __M_str.end());
    }
    else 
    {
        __M_str.append(__app_size, __char);
        __data_ptr = __M_str.begin();
    }

    setp(__data_ptr, __M_str.end());
    pbump(static_cast<int>(__M_str.size()));
    __nwritten += __app_size;
    return __nwritten;
}
Ejemplo n.º 29
0
streamsize stringbuf::xsputn(const char_type* __string, streamsize __length) 
{
    if (((__M_mode & ios_base::out) == 0) || (__length <= 0)) return 0;

    streamsize __nwritten = 0;

    // If the put pointer is somewhere in the middle of the string, then overwrite instead of append.
    if (!__M_str.empty() && (pbase() == __M_str.begin()))
    {
        ptrdiff_t __avail = __M_str.end() - pptr();
        if (__avail >= __length)
        {
            VOS_memcpy_s(pptr(), epptr() - pptr(), __string, static_cast<size_t>(__length));
            pbump(static_cast<int>(__length));
            return __length;
        }
        else 
        {
            VOS_memcpy_s(pptr(), epptr() - pptr(), __string, __avail);
            __nwritten += __avail;
            __length -= __avail;
            __string += __avail;
        }
    }

    // At this point we know we're appending.
    char_type* __data_ptr;
    if (__M_mode & ios_base::in) 
    {
        ptrdiff_t __get_offset = gptr() - eback();
        __M_str.append(__string, __string + static_cast<ptrdiff_t>(__length));
        __data_ptr = __M_str.begin();
        setg(__data_ptr, __data_ptr + __get_offset, __M_str.end());
    }
    else 
    {
        __M_str.append(__string, __string + static_cast<ptrdiff_t>(__length));
        __data_ptr = __M_str.begin();
    }

    setp(__data_ptr, __M_str.end());
    pbump(static_cast<int>(__M_str.size()));
    __nwritten += __length;
    return __nwritten;
}
Ejemplo n.º 30
0
mem_streambuf::int_type mem_streambuf::overflow( int_type c ) {
  if ( traits_type::eq_int_type( c, traits_type::eof() ) )
    return traits_type::not_eof( c );
  if ( pptr() >= epptr() )
    return traits_type::eof();
  *pptr() = traits_type::to_char_type( c );
  pbump( 1 );
  return c;
}