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

version» Context lines:

pike.git/src/modules/_Stdio/buffer.cmod:958:    *!    *! If no bytes have been written successfully 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;    ptrdiff_t written = 0, nbytes = (ptrdiff_t)(((size_t)~0)>>1);    struct my_file *fd;    ptrdiff_t sz = io_len( io ); +  int write_fun_num; +  struct inherit *inh;       if( !sz )    {    io_range_error(io, sz);    sz = io_len(io);    }    if( _nbytes )    nbytes = _nbytes->u.integer;    -  if( (fd = get_storage( f, file_program )) ) +  if ((write_fun_num = find_identifier("write", f->prog)) == -1) { +  Pike_error("Cannot call unknown function \"write\".\n"); +  } +  +  inh = INHERIT_FROM_INT(f->prog, write_fun_num); +  +  if( inh->prog == file_program )    { -  +  fd = get_inherit_storage( f, inh - f->prog->inherits ); +     /* lock this object. */    while( sz > written && nbytes )    {    ptrdiff_t rd = MINIMUM(MINIMUM(sz-written,4096),nbytes);    unsigned char *ptr = io_read_pointer( io );    ptrdiff_t res;    res = fd_write( fd->box.fd, ptr, rd );    if( res == -1 && errno == EINTR )    continue;    if( res <= 0 ) {