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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:400:    rew->rewind_to = io->len;    SET_ONERROR( (*x), io_do_unwrite_on_error, rew );    }       static void io_unset_unwrite_on_error( IOBuffer *UNUSED(io), ONERROR *x )    {    UNSET_ONERROR( (*x) );    free( x->arg );    }    -  static ssize_t io_call_write( IOBuffer *io, struct object *o, ssize_t nbytes ) +  static ptrdiff_t io_call_write( IOBuffer *io, struct object *o, ptrdiff_t nbytes )    ATTRIBUTE((noclone,noinline));       static void io_set_events( IOBuffer *io, struct my_file *fd, int extra, int set )    ATTRIBUTE((noclone,noinline));       static void io_set_events( IOBuffer *UNUSED(io), struct my_file *fd, int extra, int set )    {    fd->box.revents &= ~((1<<set)|extra);    if(!SAFE_IS_ZERO(&fd->event_cbs[set]) && fd->box.backend)    set_fd_callback_events(&fd->box, fd->box.events|(1<<set), 0);    }    -  static ssize_t io_call_write( IOBuffer *io, struct object *o, ssize_t bytes ) +  static ptrdiff_t io_call_write( IOBuffer *io, struct object *o, ptrdiff_t bytes )    {    if( bytes > 0 )    { -  ssize_t l = 0; +  ptrdiff_t l = 0;    struct pike_string *s = io_read_string( io,bytes );       if( s )    {    io->output_triggered = 1;    push_string( s );    apply( o, "write", 1 );    l = Pike_sp[-1].u.integer;    pop_stack();    if( l < 0 )
pike.git/src/modules/_Stdio/buffer.cmod:455:    if( (fd = get_storage( io->output, file_program )) )    {    io_set_events( io, fd, PIKE_BIT_FD_WRITE_OOB, PIKE_FD_WRITE );    io->output_triggered = 1;    }    else    io_call_write( io, io->output, MINIMUM( io_len(io), 100 ) );    }    }    -  static int io_range_error( IOBuffer *io, ssize_t howmuch ) +  static int io_range_error( IOBuffer *io, ptrdiff_t howmuch )    ATTRIBUTE((noclone,noinline));    -  static int io_range_error( IOBuffer *io, ssize_t howmuch ) +  static int io_range_error( IOBuffer *io, ptrdiff_t howmuch )    {    int res;    struct svalue *osp = Pike_sp;       push_int64( howmuch );    apply_current( f_IOBuffer_range_error_fun_num, 1 );    res = Pike_sp[-1].u.integer;    pop_n_elems( Pike_sp-osp );    if( !res ) io_range_error_throw( io, howmuch );       return res;    }    -  static int io_avail( IOBuffer *io, ssize_t len ) +  static int io_avail( IOBuffer *io, ptrdiff_t len )    {    if( len < 0 || len + io->offset > io->len )    {    if( len < 0 )    io_range_error_throw( io, 0 );    else if( io_range_error( io, len+io->len-io->offset ) )    return io_avail(io,len);    return 0;    }    return 1;    }    -  static int io_avail_mul( IOBuffer *io, ssize_t len, ssize_t each ) +  static int io_avail_mul( IOBuffer *io, ptrdiff_t len, ptrdiff_t each )    {    /* safely check if len*each is available. */    size_t total = io_len(io);    if( len < 0 || each <= 0 )    {    io_range_error_throw( io, 0 );    return 0;    }       if( (total/(size_t)each) < (size_t)len )
pike.git/src/modules/_Stdio/buffer.cmod:955:    *!    *! @returns    *! Will return the number of bytes that were successfully written.    *!    *! If no bytes were successfully written and @expr{f->write()@} failed    *! with an error @expr{-1@} will be returned.    */    PIKEFUN int(-1..) output_to( object f, int|void _nbytes )    {    IOBuffer *io = THIS; -  ssize_t written = 0, nbytes = (ssize_t)(((size_t)~0)>>1); +  ptrdiff_t written = 0, nbytes = (ptrdiff_t)(((size_t)~0)>>1);    struct my_file *fd; -  ssize_t sz = io_len( io ); +  ptrdiff_t sz = io_len( io );       if( !sz )    {    io_range_error(io, sz);    sz = io_len(io);    }    if( _nbytes )    nbytes = _nbytes->u.integer;       if( (fd = get_storage( f, file_program )) )    {    /* lock this object. */    while( sz > written && nbytes )    { -  ssize_t rd = MINIMUM(MINIMUM(sz-written,4096),nbytes); +  ptrdiff_t rd = MINIMUM(MINIMUM(sz-written,4096),nbytes);    unsigned char *ptr = io_read_pointer( io ); -  ssize_t res; +  ptrdiff_t res;    res = fd_write( fd->box.fd, ptr, rd );    if( res == -1 && errno == EINTR )    continue;    if( res <= 0 ) {    fd->my_errno = errno;    if (!written) written = -1;    break;    }    io_consume( io, res );    written += res;    nbytes-=res;    }    io_set_events( io, fd, PIKE_BIT_FD_WRITE_OOB, PIKE_FD_WRITE);    }    else    {    /* some other object. Just call write */    while( sz > written && nbytes)    {    size_t rd = MINIMUM(MINIMUM(sz-written,4096),nbytes); -  ssize_t wr = io_call_write( io, f, rd ); +  ptrdiff_t wr = io_call_write( io, f, rd );    if( wr <= 0 )    {    io_rewind(io, rd );    if (!written) written = -1;    break;    }    written += wr;    if( wr < 4096 ) {    io_rewind(io, rd-wr );    break;
pike.git/src/modules/_Stdio/buffer.cmod:1198:    *! Errors can occur if one of the elements in @[integers] is not    *! actually an integer, if sizeof(integers)*len is bigger than can    *! be represented in a size_t, or if the buffer cannot grow due to    *! an out of memory condition.    */    PIKEFUN IOBuffer add_ints( array(int) a, int bpi )    {    int i,l = a->size;    struct svalue *it = a->item;    unsigned char *ptr; -  ssize_t n; +  ptrdiff_t n;    ONERROR e;    IOBuffer *io = THIS;       io_unwrite_on_error(io, &e);       if( bpi < 0 )    Pike_error("Illegal int width\n");      #if SIZEOF_SIZE_T == 4    if( DO_INT32_MUL_OVERFLOW( l, bpi, &n ) )   #else    if( DO_INT64_MUL_OVERFLOW( l, bpi, &n ) )   #endif -  Pike_error("Result size exceeds ssize_t size\n"); +  Pike_error("Result size exceeds ptrdiff_t size\n");       io_add_space( io, n, 0 );    switch( bpi )    {    case 1:    for( i=0; i<l; i++ )    io_append_byte_uc( io, get_small_int(it+i) );    break;    case 2:    for( i=0; i<l; i++ )