Branch: Tag:

2015-11-24

2015-11-24 16:15:49 by Arne Goedeke <el@laramies.com>

Stdio.Buffer: added truncate()

2099:    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.