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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:1267:    p[2] = i>>8;    p[3] = i;    io->len += 4;    ref_push_object(Pike_fp->current_object);    }       /*! @decl Buffer add_hstring( string(0..255) data, int size_size )    *! @decl Buffer add_hstring( Stdio.Buffer data, int size_size )    *! @decl Buffer add_hstring( System.Memory data, int size_size )    *! @decl Buffer add_hstring( String.Buffer data, int size_size ) +  *! @decl Buffer add_hstring( int(0..255) data, int size_size )    *! @decl Buffer add_hstring( array data, int size_size ) -  +  *! @decl Buffer add_hstring( +  *! int|string(0..255)|Stdio.Buffer|System.Memory|array data, +  *! int size_size, int offset )    *!    *! Adds length of data followed by @[data] to the buffer.    *!    *! This is identical to    *! @tt{sprintf("%"+size_size+"H",(string)Stdio.Buffer(data))@} but    *! significantly faster.    *!    *! @[size_size] is the number of bytes used to represent the length of the data.    *! It must be less than Int.NATIVE_MAX.    *! -  +  *! @[offset] is added to the length of the data prior to writing out +  *! the length. Typical usage involves adding @[size_size] to account +  *! for the room used by the size. +  *!    *! The supported @[data] argument types are    *!    *! @mixed -  +  *! @type int(0..255) +  *! An eight bit character.    *! @type string(0..255)    *! An eight bit string.    *! @type System.Memory    *! A chunk of memory. The whole memory area is added.    *! @type Stdio.Buffer    *! A chunk of memory. The whole memory area is added.    *! @type String.Buffer    *! A chunk of memory. The whole memory area is added.    *! @type array    *! Add all elements in the array individually. Each element may be    *! any one of the types listed here.    *! @endmixed    */       /* we can not use the actual type here.       the reason is that this class is loaded before the master is, so    we cannot possibly use things that require the master (such as    resolving things.)    */ -  PIKEFUN Buffer add_hstring( string|object|array(string|Buffer|array) str, int size_size ) +  PIKEFUN Buffer add_hstring( +  int|string|object|array(int|string|Buffer|array) str, +  int size_size, void|int offset )    {    Buffer *io = THIS;    size_t len = io_svalue_len(io, str);    -  +  if( offset ) +  len += offset->u.integer; +     if( size_size < (int)sizeof(size_t) &&    len > (((size_t)1)<<(8*size_size))-1 )    Pike_error("Too long string, need larger size field\n");       io_add_int( io, len, size_size );    io_append_svalue( io, str );    pop_n_elems(args);    ref_push_object(io->this);    }   
pike.git/src/modules/_Stdio/buffer.cmod:1642:    case 'q':    push_text("%q");    push_string( io_read_string( THIS, io_len(THIS)) );    f_sprintf(2);    break;    default:    push_undefined();    }    }    -  /*! @decl string(8bit) read_hstring( int(0..) n ) +  /*! @decl string(8bit) read_hstring( int(0..) n, void|int offset )    *!    *! Identical in functionality to @[read](@[read_number](@[n])) but    *! faster.    *!    *! Read a network byte order number of size n*8 bits, then return the    *! indicated number of bytes as a string.    *! -  +  *! @[offset] is substracted from the specified length prior to reading the +  *! string. Typical usage involves substracting @[n] to account +  *! for the room used by the size. +  *!    *! If there is not enough data available return 0.    *!    *! Note that pike string can not be longer than 0x7fffffff bytes (~2Gb).    */ -  PIKEFUN string(0..255) read_hstring( int bytes ) +  PIKEFUN string(0..255) read_hstring( int bytes, void|int offset )    {    LONGEST len;    Buffer *io = THIS;    struct pike_string *s;    ONERROR e;       io_rewind_on_error( io, &e );    len = io_read_number( io, bytes );    -  +  if (offset) +  len -= offset->u.integer; +     if (len < 0) {    /* io_avail() in io_read_number() failed. */    CALL_AND_UNSET_ONERROR(e);    Pike_sp[-1].u.integer = 0;    return;    }       /* NB: We assume that io_avail() in io_read_string() doesn't throw. */    s = io_read_string( io, len );