summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-07-24 09:07:33 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-07-24 09:07:33 +0000
commit15ffbb1f820be7c798a7eb0aa2be11b5d4207460 (patch)
treef27d9d12e2cda0dca1435e1f0567d9fb423c7230 /io.c
parent9e214f30c4f2bb6e6529c1bb988be1e46026919f (diff)
* eval.c (rb_provide_feature): should not tweak extension used for
loading. * io.c (io_fread): use fread(3) if PENDING_COUND is available. * class.c (rb_mod_include_p): Module#include? added. [new] * re.c (ignorecase_setter): give warning on modifying $=. * string.c (rb_str_casecmp): new method. [new] * string.c (rb_str_eql): separated from rb_str_equal(), make it always be case sensitive. [new] * string.c (rb_str_hash): made it always be case sensitive. * eval.c (rb_f_require): should not include path in $" value * file.c (rb_find_file): should return 0 explicitly on failure. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1642 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/io.c b/io.c
index 2c51dec6e1..448fd60032 100644
--- a/io.c
+++ b/io.c
@@ -108,11 +108,14 @@ static VALUE lineno;
#ifdef _STDIO_USES_IOSTREAM /* GNU libc */
# ifdef _IO_fpos_t
# define READ_DATA_PENDING(fp) ((fp)->_IO_read_ptr != (fp)->_IO_read_end)
+# define READ_DATA_PENDING_COUNT(fp) ((fp)->_IO_read_end - (fp)->_IO_read_ptr)
# else
# define READ_DATA_PENDING(fp) ((fp)->_gptr < (fp)->_egptr)
+# define READ_DATA_PENDING_COUNT(fp) ((fp)->_egptr - (fp)->_gptr)
# endif
#elif defined(FILE_COUNT)
# define READ_DATA_PENDING(fp) ((fp)->FILE_COUNT > 0)
+# define READ_DATA_PENDING_COUNT(fp) ((fp)->FILE_COUNT)
#elif defined(__BEOS__)
# define READ_DATA_PENDING(fp) (fp->_state._eof == 0)
#else
@@ -476,14 +479,34 @@ io_fread(ptr, len, f)
long n = len;
int c;
- while (n--) {
+ while (n > 0) {
+#ifdef READ_DATA_PENDING_COUNT
+ int i = READ_DATA_PENDING_COUNT(f);
+ if (i <= 0) {
+ rb_thread_wait_fd(fileno(f));
+ i = READ_DATA_PENDING_COUNT(f);
+ }
+ if (i > 0) {
+ if (i > n) i = n;
+ TRAP_BEG;
+ c = fread(ptr, 1, i, f);
+ TRAP_END;
+ if (c < 0) goto eof;
+ ptr += c;
+ n -= c;
+ if (c < i) goto eof;
+ continue;
+ }
+#else
if (!READ_DATA_PENDING(f)) {
rb_thread_wait_fd(fileno(f));
}
+#endif
TRAP_BEG;
c = getc(f);
TRAP_END;
if (c == EOF) {
+ eof:
if (ferror(f)) {
if (errno == EINTR) continue;
rb_sys_fail(0);
@@ -492,9 +515,10 @@ io_fread(ptr, len, f)
break;
}
*ptr++ = c;
+ n--;
}
- return len - n - 1;
+ return len - n;
}
#ifndef S_ISREG