summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-27 02:21:53 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-27 02:21:53 +0000
commite8fe520ecdd0a5b7af377c56108be2741777e681 (patch)
treed2e4c6ba12cfbe19687103e6b5611847b5c03c1f /io.c
parentf7987213342edf6dd58d221a08f2f80074e92eee (diff)
* io.c (io_fread): [ruby-dev:24964]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7387 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c45
1 files changed, 30 insertions, 15 deletions
diff --git a/io.c b/io.c
index 2d447c1..8e1dbba 100644
--- a/io.c
+++ b/io.c
@@ -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;