* io.c (io_fread): [ruby-dev:24964]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2004-11-27 02:21:53 +00:00
parent 27c24b0f3b
commit 65445b53ca
2 changed files with 29 additions and 10 deletions

View File

@ -1,3 +1,7 @@
Sat Nov 27 09:41:21 2004 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_fread): [ruby-dev:24964]
Fri Nov 26 18:02:44 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> Fri Nov 26 18:02:44 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tk/lib/tk.rb: Tk.destroy uses TkWindow#epath * ext/tk/lib/tk.rb: Tk.destroy uses TkWindow#epath

35
io.c
View File

@ -939,41 +939,42 @@ read_buffered_data(ptr, len, f)
} }
long long
rb_io_fread(ptr, len, f) io_fread(ptr, len, fptr)
char *ptr; char *ptr;
long len; long len;
FILE *f; OpenFile *fptr;
{ {
long n = len; long n = len;
int c; int c;
while (n > 0) { while (n > 0) {
c = read_buffered_data(ptr, n, f); c = read_buffered_data(ptr, n, fptr->f);
if (c < 0) goto eof; if (c < 0) goto eof;
if (c > 0) { if (c > 0) {
ptr += c; ptr += c;
if ((n -= c) <= 0) break; if ((n -= c) <= 0) break;
} }
rb_thread_wait_fd(fileno(f)); rb_thread_wait_fd(fileno(fptr->f));
rb_io_check_closed(fptr);
TRAP_BEG; TRAP_BEG;
c = getc(f); c = getc(fptr->f);
TRAP_END; TRAP_END;
if (c == EOF) { if (c == EOF) {
eof: eof:
if (ferror(f)) { if (ferror(fptr->f)) {
switch (errno) { switch (errno) {
case EINTR: case EINTR:
#if defined(ERESTART) #if defined(ERESTART)
case ERESTART: case ERESTART:
#endif #endif
clearerr(f); clearerr(fptr->f);
continue; continue;
case EAGAIN: case EAGAIN:
#if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN
case EWOULDBLOCK: case EWOULDBLOCK:
#endif #endif
if (len > n) { if (len > n) {
clearerr(f); clearerr(fptr->f);
} }
} }
if (len == n) return 0; if (len == n) return 0;
@ -987,6 +988,19 @@ rb_io_fread(ptr, len, f)
return len - n; 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 #ifndef S_ISREG
# define S_ISREG(m) ((m & S_IFMT) == S_IFREG) # define S_ISREG(m) ((m & S_IFMT) == S_IFREG)
#endif #endif
@ -1038,7 +1052,7 @@ read_all(fptr, siz, str)
for (;;) { for (;;) {
rb_str_locktmp(str); rb_str_locktmp(str);
READ_CHECK(fptr->f); 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); rb_str_unlocktmp(str);
if (n == 0 && bytes == 0) { if (n == 0 && bytes == 0) {
rb_str_resize(str,0); rb_str_resize(str,0);
@ -1226,7 +1240,7 @@ io_read(argc, argv, io)
if (RSTRING(str)->len != len) { if (RSTRING(str)->len != len) {
rb_raise(rb_eRuntimeError, "buffer string modified"); 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); rb_str_unlocktmp(str);
if (n == 0) { if (n == 0) {
rb_str_resize(str,0); rb_str_resize(str,0);
@ -2274,6 +2288,7 @@ rb_io_sysread(argc, argv, io)
} }
n = fileno(fptr->f); n = fileno(fptr->f);
rb_thread_wait_fd(fileno(fptr->f)); rb_thread_wait_fd(fileno(fptr->f));
rb_io_check_closed(fptr);
TRAP_BEG; TRAP_BEG;
n = read(fileno(fptr->f), RSTRING(str)->ptr, RSTRING(str)->len); n = read(fileno(fptr->f), RSTRING(str)->ptr, RSTRING(str)->len);
TRAP_END; TRAP_END;