pike.git / src / modules / _Stdio / buffer.cmod

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:2092:    */    PIKEFUN int(-1..) consume( int n )    {    Pike_sp--;    if( !io_avail( THIS, n ) )    push_int(-1);    else    push_int64( io_consume( THIS, n ) );    }    +  /*! @decl int(0..)|int(-1..-1) truncate( int(0..) n ) +  *! +  *! Truncates the buffer to a length of @[n] bytes. +  *! +  *! Returns -1 on error and the number of bytes removed otherwise. +  */ +  PIKEFUN int(-1..) truncate( int(0..) n ) +  { +  Buffer *io = THIS; +  ptrdiff_t diff = io_len(io) - n; +  Pike_sp--;    -  +  if( diff < 0 || io_len(io) < (size_t)diff ) +  push_int(-1); +  else { +  io->len -= diff; +  push_int64( diff ); +  } +  } +     /*! @decl int(0..)|int(-1..-1) unread( int(0..) n )    *!    *! Rewind the buffer @[n] bytes.    *!    *! @returns    *!    *! This function returns how many more bytes of buffer is    *! available to rewind, or -1 on error.    *!    *! @note