summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-09 08:05:32 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2003-01-09 08:05:32 +0000
commit99628bf1f0f401ef2ad877675321432ebb9a7586 (patch)
tree26c8cdcbb0f6a28883ad894bcfae033df866b1ce /io.c
parent639ec768584589b8ebfc98dcb41dfe8db76a1aba (diff)
* configure.in (RUBY_CHECK_IO_NEED): check whether fseek() and
fflush() are needed. * io.c (flush_before_seek): flush write stream only. * io.c (rb_io_check_readable): seek instead of flush if the last operation was write. * io.c (rb_io_check_writable): seek instead of flush if the last operation was read. * bcc32/Makefile.sub, win32/Makefile.sub: needs to seek between R/W. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@3318 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c28
1 files changed, 12 insertions, 16 deletions
diff --git a/io.c b/io.c
index 0c2ba4d..fd612dd 100644
--- a/io.c
+++ b/io.c
@@ -195,12 +195,8 @@ static OpenFile *
flush_before_seek(fptr)
OpenFile *fptr;
{
- int mode = fptr->mode;
- if (mode & FMODE_RBUF) {
- if (!fptr->f2) io_fflush(fptr->f, fptr);
- }
- if (mode & FMODE_WBUF) {
- io_fflush((fptr->f2 ? fptr->f2 : fptr->f), fptr);
+ if (fptr->mode & FMODE_WBUF) {
+ io_fflush(GetWriteFile(fptr), fptr);
}
return fptr;
}
@@ -211,6 +207,12 @@ flush_before_seek(fptr)
#define io_seek(fptr, ofs, whence) fseeko(flush_before_seek(fptr)->f, ofs, whence)
#define io_tell(fptr) ftello(flush_before_seek(fptr)->f)
+#ifndef SEEK_CUR
+# define SEEK_SET 0
+# define SEEK_CUR 1
+# define SEEK_END 2
+#endif
+
void
rb_io_check_readable(fptr)
OpenFile *fptr;
@@ -218,9 +220,9 @@ rb_io_check_readable(fptr)
if (!(fptr->mode & FMODE_READABLE)) {
rb_raise(rb_eIOError, "not opened for reading");
}
-#if NEED_IO_FLUSH_BETWEEN_RW
+#if NEED_IO_SEEK_BETWEEN_RW
if ((fptr->mode & FMODE_WBUF) && !fptr->f2) {
- io_fflush(fptr->f, fptr);
+ io_seek(fptr, 0, SEEK_CUR);
}
fptr->mode |= FMODE_RBUF;
#endif
@@ -233,9 +235,9 @@ rb_io_check_writable(fptr)
if (!(fptr->mode & FMODE_WRITABLE)) {
rb_raise(rb_eIOError, "not opened for writing");
}
-#if NEED_IO_FLUSH_BETWEEN_RW
+#if NEED_IO_SEEK_BETWEEN_RW
if ((fptr->mode & FMODE_RBUF) && !fptr->f2) {
- io_fflush(fptr->f, fptr);
+ io_seek(fptr, 0, SEEK_CUR);
}
#endif
}
@@ -472,12 +474,6 @@ rb_io_tell(io)
return OFFT2NUM(pos);
}
-#ifndef SEEK_CUR
-# define SEEK_SET 0
-# define SEEK_CUR 1
-# define SEEK_END 2
-#endif
-
static VALUE
rb_io_seek(io, offset, whence)
VALUE io, offset;