aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-21 04:56:06 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-01-21 04:56:06 +0000
commit877dca1e272e5582bd739fb4fed90ef8209e5095 (patch)
tree569908a38e1f289f529f3c650ad08989557ecf82
parent8029f3d2996de5500fa2d700b06d7160f7fff18e (diff)
downloadruby-877dca1e272e5582bd739fb4fed90ef8209e5095.tar.gz
* include/ruby/io.h (typedef struct rb_io_t):
* io.c (flush_before_seek): * io.c (io_fillbuf): * io.c (io_fread): * io.c (io_getpartial): * ruby.c (load_file_internal): git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@21709 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog9
-rw-r--r--include/ruby/io.h1
-rw-r--r--io.c18
3 files changed, 25 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index aaa8098b5f..c9b1d1d28e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+Wed Jan 21 13:57:18 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * include/ruby/io.h (typedef struct rb_io_t):
+ * io.c (flush_before_seek):
+ * io.c (io_fillbuf):
+ * io.c (io_fread):
+ * io.c (io_getpartial):
+ * ruby.c (load_file_internal):
+
Wed Jan 21 08:22:04 2009 Ryan Davis <ryand-ruby@zenspider.com>
* lib/minitest/*.rb: Imported minitest 1.3.1 r4532.
diff --git a/include/ruby/io.h b/include/ruby/io.h
index 04af3d07e3..64773549f5 100644
--- a/include/ruby/io.h
+++ b/include/ruby/io.h
@@ -92,6 +92,7 @@ typedef struct rb_io_t {
#define FMODE_WSPLIT_INITIALIZED 0x00000400
#define FMODE_TRUNC 0x00000800
#define FMODE_TEXTMODE 0x00001000
+#define FMODE_EOF 0x00002000
/* #define FMODE_PREP 0x00010000 */
#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)
diff --git a/io.c b/io.c
index c302156a03..16f37cda39 100644
--- a/io.c
+++ b/io.c
@@ -353,7 +353,8 @@ flush_before_seek(rb_io_t *fptr)
return fptr;
}
-#define io_seek(fptr, ofs, whence) lseek(flush_before_seek(fptr)->fd, ofs, whence)
+#define io_set_eof(fptr) (void)(((fptr)->mode & FMODE_TTY) && ((fptr)->mode |= FMODE_EOF))
+#define io_seek(fptr, ofs, whence) (fptr->mode &= ~FMODE_EOF, lseek(flush_before_seek(fptr)->fd, ofs, whence))
#define io_tell(fptr) lseek(flush_before_seek(fptr)->fd, 0, SEEK_CUR)
#ifndef SEEK_CUR
@@ -1147,6 +1148,9 @@ io_fillbuf(rb_io_t *fptr)
{
int r;
+ if (fptr->mode & FMODE_EOF) {
+ return -1;
+ }
if (fptr->rbuf == NULL) {
fptr->rbuf_off = 0;
fptr->rbuf_len = 0;
@@ -1165,8 +1169,10 @@ io_fillbuf(rb_io_t *fptr)
}
fptr->rbuf_off = 0;
fptr->rbuf_len = r;
- if (r == 0)
+ if (r == 0) {
+ io_set_eof(fptr);
return -1; /* EOF */
+ }
}
return 0;
}
@@ -1436,7 +1442,10 @@ io_fread(VALUE str, long offset, rb_io_t *fptr)
if (READ_DATA_PENDING(fptr) == 0) {
while (n > 0) {
c = rb_read_internal(fptr->fd, RSTRING_PTR(str)+offset, n);
- if (c == 0) break;
+ if (c == 0) {
+ io_set_eof(fptr);
+ break;
+ }
if (c < 0) {
rb_sys_fail_path(fptr->pathv);
}
@@ -1743,6 +1752,9 @@ io_getpartial(int argc, VALUE *argv, VALUE io, int nonblock)
goto again;
rb_sys_fail_path(fptr->pathv);
}
+ else if (n == 0) {
+ io_set_eof(fptr);
+ }
}
rb_str_resize(str, n);