1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* io.c (rb_io_fread): renamed from io_fread and made extern.

* marshal.c (r_bytes0): check if successfully read, use
  rb_io_fread() instead of fread() to be preemptive.
  (ruby-bugs-ja:PR#294, 295)

* rubyio.h (rb_io_fread): added.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2713 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2002-08-16 02:52:25 +00:00
parent 3d923fb928
commit 2229b70615
4 changed files with 20 additions and 6 deletions

View file

@ -1,3 +1,13 @@
Fri Aug 16 11:47:24 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* io.c (rb_io_fread): renamed from io_fread and made extern.
* marshal.c (r_bytes0): check if successfully read, use
rb_io_fread() instead of fread() to be preemptive.
(ruby-bugs-ja:PR#294, 295)
* rubyio.h (rb_io_fread): added.
Fri Aug 16 07:57:26 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net> Fri Aug 16 07:57:26 2002 Nobuyoshi Nakada <nobu.nokada@softhome.net>
* eval.c (compile_error): must not clear ruby_sourcefile here. * eval.c (compile_error): must not clear ruby_sourcefile here.

8
io.c
View file

@ -542,8 +542,8 @@ rb_io_to_io(io)
/* reading functions */ /* reading functions */
static long long
io_fread(ptr, len, f) rb_io_fread(ptr, len, f)
char *ptr; char *ptr;
long len; long len;
FILE *f; FILE *f;
@ -650,7 +650,7 @@ read_all(fptr, siz)
if (!siz) siz = BUFSIZ; if (!siz) siz = BUFSIZ;
str = rb_tainted_str_new(0, siz); str = rb_tainted_str_new(0, siz);
for (;;) { for (;;) {
n = io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f); n = rb_io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f);
if (n == 0 && bytes == 0) { if (n == 0 && bytes == 0) {
if (feof(fptr->f)) return Qnil; if (feof(fptr->f)) return Qnil;
rb_sys_fail(fptr->path); rb_sys_fail(fptr->path);
@ -694,7 +694,7 @@ io_read(argc, argv, io)
if (len == 0) return str; if (len == 0) return str;
READ_CHECK(fptr->f); READ_CHECK(fptr->f);
n = io_fread(RSTRING(str)->ptr, len, fptr->f); n = rb_io_fread(RSTRING(str)->ptr, len, fptr->f);
if (n == 0) { if (n == 0) {
if (feof(fptr->f)) return Qnil; if (feof(fptr->f)) return Qnil;
rb_sys_fail(fptr->path); rb_sys_fail(fptr->path);

View file

@ -712,11 +712,14 @@ r_bytes0(s, len, arg)
struct load_arg *arg; struct load_arg *arg;
{ {
if (arg->fp) { if (arg->fp) {
len = fread(s, 1, len, arg->fp); if (rb_io_fread(s, len, arg->fp) != len) {
too_short:
rb_raise(rb_eArgError, "marshal data too short");
}
} }
else { else {
if (arg->ptr + len > arg->end) { if (arg->ptr + len > arg->end) {
len = arg->end - arg->ptr; goto too_short;
} }
memcpy(s, arg->ptr, len); memcpy(s, arg->ptr, len);
arg->ptr += len; arg->ptr += len;

View file

@ -57,6 +57,7 @@ typedef struct OpenFile {
FILE *rb_fopen _((const char*, const char*)); FILE *rb_fopen _((const char*, const char*));
FILE *rb_fdopen _((int, const char*)); FILE *rb_fdopen _((int, const char*));
int rb_getc _((FILE*)); int rb_getc _((FILE*));
long rb_io_fread _((char *, long, FILE *));
int rb_io_mode_flags _((const char*)); int rb_io_mode_flags _((const char*));
void rb_io_check_writable _((OpenFile*)); void rb_io_check_writable _((OpenFile*));
void rb_io_check_readable _((OpenFile*)); void rb_io_check_readable _((OpenFile*));