diff options
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 45 |
1 files changed, 30 insertions, 15 deletions
@@ -903,25 +903,26 @@ rb_io_to_io(io) /* reading functions */ long -rb_io_fread(ptr, len, f) +io_fread(ptr, len, fptr) char *ptr; long len; - FILE *f; + OpenFile *fptr; { long n = len; int c; while (n > 0) { #ifdef READ_DATA_PENDING_COUNT - long i = READ_DATA_PENDING_COUNT(f); + long i = READ_DATA_PENDING_COUNT(fptr->f); if (i <= 0) { - rb_thread_wait_fd(fileno(f)); - i = READ_DATA_PENDING_COUNT(f); + rb_thread_wait_fd(fileno(fptr->f)); + rb_io_check_closed(fptr); + i = READ_DATA_PENDING_COUNT(fptr->f); } if (i > 0) { if (i > n) i = n; TRAP_BEG; - c = fread(ptr, 1, i, f); + c = fread(ptr, 1, i, fptr->f); TRAP_END; if (c < 0) goto eof; ptr += c; @@ -930,31 +931,31 @@ rb_io_fread(ptr, len, f) continue; } #else - if (!READ_DATA_PENDING(f)) { - rb_thread_wait_fd(fileno(f)); + if (!READ_DATA_PENDING(fptr->f)) { + rb_thread_wait_fd(fileno(fptr->f)); + rb_io_check_closed(fptr); } #endif TRAP_BEG; - c = getc(f); + c = getc(fptr->f); TRAP_END; if (c == EOF) { eof: - if (ferror(f)) { + if (ferror(fptr->f)) { switch (errno) { case EINTR: #if defined(ERESTART) case ERESTART: #endif - clearerr(f); + clearerr(fptr->f); continue; case EAGAIN: #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN case EWOULDBLOCK: #endif if (len > n) { - clearerr(f); + clearerr(fptr->f); } - rb_thread_wait_fd(fileno(f)); } if (len == n) return 0; } @@ -967,6 +968,19 @@ rb_io_fread(ptr, len, f) return len - n; } +long +rb_io_fread(ptr, len, f) + char *ptr; + long len; + FILE *f; +{ + OpenFile of; + + of.f = f; + of.f2 = NULL; + return io_fread(ptr, len, &of); +} + #ifndef S_ISREG # define S_ISREG(m) ((m & S_IFMT) == S_IFREG) #endif @@ -1018,7 +1032,7 @@ read_all(fptr, siz, str) for (;;) { rb_str_locktmp(str); READ_CHECK(fptr->f); - n = rb_io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr->f); + n = io_fread(RSTRING(str)->ptr+bytes, siz-bytes, fptr); rb_str_unlocktmp(str); if (n == 0 && bytes == 0) { rb_str_resize(str,0); @@ -1094,7 +1108,7 @@ io_read(argc, argv, io) if (RSTRING(str)->len != len) { rb_raise(rb_eRuntimeError, "buffer string modified"); } - n = rb_io_fread(RSTRING(str)->ptr, len, fptr->f); + n = io_fread(RSTRING(str)->ptr, len, fptr); rb_str_unlocktmp(str); if (n == 0) { rb_str_resize(str,0); @@ -2131,6 +2145,7 @@ rb_io_sysread(argc, argv, io) } n = fileno(fptr->f); rb_thread_wait_fd(fileno(fptr->f)); + rb_io_check_closed(fptr); TRAP_BEG; n = read(fileno(fptr->f), RSTRING(str)->ptr, RSTRING(str)->len); TRAP_END; |