Bug #8669 » io_fread.diff
io.c | ||
---|---|---|
static void io_setstrbuf(VALUE *str, long len);
|
||
struct bufread_arg {
|
||
char *str_ptr;
|
||
long len;
|
||
rb_io_t *fptr;
|
||
};
|
||
static VALUE
|
||
bufread_call(VALUE arg)
|
||
{
|
||
struct bufread_arg *p = (struct bufread_arg *)arg;
|
||
p->len = io_bufread(p->str_ptr, p->len, p->fptr);
|
||
return Qundef;
|
||
}
|
||
static long
|
||
io_fread(VALUE str, long offset, long size, rb_io_t *fptr)
|
||
{
|
||
long len;
|
||
struct bufread_arg arg;
|
||
io_setstrbuf(&str, offset + size);
|
||
rb_str_locktmp(str);
|
||
len = io_bufread(RSTRING_PTR(str) + offset, size, fptr);
|
||
rb_str_unlocktmp(str);
|
||
arg.str_ptr = RSTRING_PTR(str) + offset;
|
||
arg.len = size;
|
||
arg.fptr = fptr;
|
||
rb_ensure(bufread_call, (VALUE)&arg, rb_str_unlocktmp, str);
|
||
len = arg.len;
|
||
if (len < 0) rb_sys_fail_path(fptr->pathv);
|
||
return len;
|
||
}
|