Exemplo n.º 1
0
int gzfilebuf::overflow( int c ) {

  if ( !is_open() || !(mode & ios::out) )
    return EOF;

  if ( !base() ) {
    if ( allocate() == EOF )
      return EOF;
    setg(0,0,0);
  } else {
    if (in_avail()) {
	return EOF;
    }
    if (out_waiting()) {
      if (flushbuf() == EOF)
	return EOF;
    }
  }

  int bl = blen();
  setp( base(), base() + bl);

  if ( c != EOF ) {

    *pptr() = c;
    pbump(1);

  }

  return 0;

}
Exemplo n.º 2
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);
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
/***
*virtual int filebuf::sync() - synchronize buffers with external file postion.
*
*Purpose:
*	Synchronizes buffer with external file, by flushing any output and/or
*	discarding any unread input data.  Discards any get or put area(s).
*
*Entry:
*	None.
*
*Exit:
*	Returns EOF if error, else 0.
*
*Exceptions:
*	Returns EOF if error.
*
*******************************************************************************/
int filebuf::sync()
{
        long count, nout;
        char * p;
        if (x_fd==-1)
            return(EOF);

        if (!unbuffered())
        {
            if ((count=out_waiting())!=0)
            {
                if ((nout =_write(x_fd,(void *) pbase(),(unsigned int)count)) != count)
                {
                    if (nout > 0) {
                        // should set _pptr -= nout
                        pbump(-(int)nout);
                        memmove(pbase(), pbase()+nout, (int)(count-nout));
                    }
                    return(EOF);
                }
            }
            setp(0,0); // empty put area

            if ((count=in_avail()) > 0)
            {
                // can't use seekoff here!!
#ifdef  _WIN32
                if (_osfile(x_fd) & FTEXT)
#else
                if (_osfile[x_fd] & FTEXT)
#endif
                {
                    // If text mode, need to account for CR/LF etc.
                    for (p = gptr(); p < egptr(); p++)
                        if (*p == '\n')
                            count++;

                    // account for EOF if read, not counted by _read
#ifdef  _WIN32
                    if ((_osfile(x_fd) & FEOFLAG))
#else
                    if ((_osfile[x_fd] & FEOFLAG))
#endif
                        count++;

                }
                if (_lseek(x_fd, -count, SEEK_CUR)==-1L)
                {
//                  unlock();
                    return (EOF);
                }
            }
            setg(0,0,0); // empty get area
        }
//      unlock();
        return(0);
}
Exemplo n.º 5
0
int gzfilebuf::sync() {

  if ( !is_open() )
    return EOF;

  if ( out_waiting() )
    return flushbuf();

  return 0;

}
Exemplo n.º 6
0
_ALControlStream::sync()
{
    int i = out_waiting();
    if ( i != 0 && pbase() != 0 ) {
        pbase()[ i ] = '\0';
        SendMessage( hWindow,
                     EM_REPLACESEL,
                     0,
                     (LPARAM) ( (LPSTR) pbase() ) );
    }
    setp( 0, 0 );
    return 0;
}
Exemplo n.º 7
0
boolean rpcbuf::expand_p() {
    int newsize = (epptr() - pbase()) * 2;
    char* put = new char[newsize];
    if (!put) {
	return false;
    }

    int nwaiting = out_waiting();
    Memory::copy(pbase(), put, nwaiting);
    delete pbase();
    setp(put, put + newsize);
    pbump(nwaiting);
    setr(put);

    return true;
}
Exemplo n.º 8
0
int 
PRfilebuf::sync()
{
    PRInt32 count; 

    if (_fd==0)
        return(EOF);

    if (!unbuffered()){
        // Sync write area
        if ((count=out_waiting())!=0){
            PRInt32 nout;
            if ((nout =PR_Write(_fd,
                               (void *) pbase(),
                               (unsigned int)count)) != count){
                if (nout > 0) {
                    // should set _pptr -= nout
                    pbump(-(int)nout);
                    memmove(pbase(), pbase()+nout, (int)(count-nout));
                }
                return(EOF);
            }
        }
        setp(0,0); // empty put area

        if (PR_GetDescType(_fd) == PR_DESC_FILE){
            // Sockets can't seek; don't need this
            if ((count=in_avail()) > 0){
                if (PR_Seek(_fd, -count, PR_SEEK_CUR)!=-1L)
                {
                    return (EOF);
                }
            }
        }
        setg(0,0,0); // empty get area
    }
    return(0);
}
Exemplo n.º 9
0
int gzfilebuf::underflow() {

  // If the file hasn't been opened for reading, error.
  if ( !is_open() || !(mode & ios::in) )
    return EOF;

  // if a buffer doesn't exists, allocate one.
  if ( !base() ) {

    if ( (allocate()) == EOF )
      return EOF;
    setp(0,0);

  } else {

    if ( in_avail() )
      return (unsigned char) *gptr();

    if ( out_waiting() ) {
      if ( flushbuf() == EOF )
	return EOF;
    }

  }

  // Attempt to fill the buffer.

  int result = fillbuf();
  if ( result == EOF ) {
    // disable get area
    setg(0,0,0);
    return EOF;
  }

  return (unsigned char) *gptr();

}
Exemplo n.º 10
0
  int strstreambuf::overflow( int c ) {
    __lock_it( __b_lock );
    if( !__dynamic ) {
        return( EOF );
    }
    if( __unlimited ) {
        // adjust end pointer
        int offset = out_waiting();
        setp( pbase(), epptr() + DEFAULT_MAINBUF_SIZE );
        pbump( offset );
        return( __NOT_EOF );
    }

    // Use doallocate() because streambuf::allocate() will not grow an
    // existing buffer the way strstreambuf needs to
    if( doallocate() == EOF ) {
        return( EOF );
    }
    if( c != EOF ) {
        *pptr() = (char)c;
        pbump( 1 );
    }
    return( __NOT_EOF );
  }
Exemplo n.º 11
0
int stdiobuf::overflow(int c)
{
    if ( ferror(sio) )
        return EOF;

    char *p;
    int count = out_waiting();
    if( count > 0 )
        {
        p = pbase();
        do  {
            putc(*p, sio);
            ++p;
            } while( --count );
        }
    if( c != EOF )
        putc(c, sio);

    char *b = base();
    setp(b+4, b+blen());
    setg(b, b+4, b+4);

    return ferror(sio) ? EOF : 1;
}
Exemplo n.º 12
0
streampos stdiobuf::seekoff(streamoff off, ios::seek_dir dir, int /*mode ignored*/)
{
    if( out_waiting()  ||  in_avail() )
        {
        if( sync() == EOF )
            return EOF;
        }

    int w;
    if( dir == ios::beg )
        w = SEEK_SET;
    else if( dir == ios::end )
        w = SEEK_END;
    else
        w = SEEK_CUR;
    w = fseek(sio, off, w);
    char *b = base();
    if( ! unbuffered()  &&  b )
        {   // reset get and put areas
        setp(b+4, b+4);
        setg(b, b+4, b+4);
        }
    return w ? EOF : ftell(sio);
}
Exemplo n.º 13
0
int rpcbuf::sync() {
    gbump(in_avail());
    return out_waiting() ? overflow() : 0;
}
Exemplo n.º 14
0
int stdiobuf::underflow() {
/*************************/
// Handle allocating a buffer, if required.
// Handle filling the get area of the streambuf.
// Read more stuff from the input device.
// Return the first character read.

    char *ptr;
    int   len;

    __lock_it( __b_lock );

    // Flush any output waiting in the buffer:
    if( out_waiting() > 0 ) {
        if( sync() == EOF ) {
            return( EOF );
        }
    }
    // discard put area
    setp( NULL, NULL );

    // Try to allocate a buffer:
    if( base() == NULL ) {
        if( allocate() == EOF ) {
            return( EOF );
        }
        if( base() == NULL ) {
            // unbuffered special case
            ptr = __unbuffered_get_area + DEFAULT_PUTBACK_SIZE;
            setg( __unbuffered_get_area, ptr, ptr );
            int ch;
            ch = fgetc( __file_pointer );
            if( ch == EOF ) {
                return( EOF );
            } else {
                *egptr() = (char)ch;
            }
            setg( eback(), gptr(), egptr() + 1 );
            return( *gptr() );
        } else {
            ptr = base() + DEFAULT_PUTBACK_SIZE;
            setg( base(), ptr, ptr );
        }
    } else if( gptr() >= egptr() ) {
        ptr = base() + DEFAULT_PUTBACK_SIZE;
        setg( base(), ptr, ptr );
    }

    len = (__huge_ptr_int)(ebuf() - egptr());
    if( len > 0 ) {
        len = 1;
        int ch;
        ch = fgetc( __file_pointer );
        if( ch == EOF ) {
            return( EOF );
        } else {
            *egptr() = (char)ch;
        }
    } else {
        len = 0;
    }
    setg( eback(), gptr(), egptr() + len );
    return( gptr() < egptr() ? *gptr() : EOF );
}