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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:1781:    if( LIKELY(s) ) {    io_read_byte_uc(io); /* consume the terminating byte */    io_unset_rewind_on_error( io, &e );    push_string(s);    } else {   fail: CALL_AND_UNSET_ONERROR(e);    push_undefined();    }    }    -  /*! @decl protected int(-1..) _search(int(8bit) character, int|void start) +  /*! @decl protected int(-1..) _search(int(8bit) character, int|void start, @ +  *! int|void end)    *!    *! Search forward from the indicated @[start] position for the specified    *! @[character].    *!    *! @param character    *! Character to search for.    *!    *! @param start    *! Start position relative to the current read position of the buffer.    *!    *! Negative @[start] values are supported and indicate positions    *! prior to the current read position.    *! -  +  *! @param end +  *! Don't search past this position of the buffer. +  *!    *! @returns    *! Returns the first found position of @[character] relative to the    *! current read position of the buffer on success, and @[UNDEFINED]    *! on not found. The read position is not advanced.    *!    *! @seealso    *! @[read_cstring()], @[search()], @[lfun::_search()]    */ -  PIKEFUN int _search(int(8bit) character, int|void start) +  PIKEFUN int _search(int(8bit) character, int|void start, int|void end)    flags ID_PROTECTED;    {    Buffer *io = THIS;    unsigned char *buf = io_read_pointer(io); -  unsigned char *buf_start = buf; +     unsigned char *buf_end = buf + io_len(io);    -  +  if (end) { +  INT_TYPE bytes = end->u.integer; +  +  if (bytes < 0) { +  push_int(-1); +  return; +  } +  if (((size_t)bytes) < io_len(io)) { +  buf_end = buf + bytes + 1; +  } +  } +     if (start) {    INT_TYPE bytes = start->u.integer; -  buf_start += bytes; +        if (bytes >= 0) {    if (((size_t)bytes) >= io_len(io)) {    push_int(-1);    return;    }    } else if (((size_t)(-bytes)) > io->offset) {    bytes = -(ptrdiff_t)io->offset;    }    buf += bytes;