From d486686eb768619714328bff86be8e7711c2e967 Mon Sep 17 00:00:00 2001 From: akr Date: Mon, 7 Feb 2005 14:18:41 +0000 Subject: [PATCH] * io.c (io_getc): flush rb_stdout before read fro stdin, which is connected to a tty. [ruby-core:4378] * rubyio.h (FMODE_TTY): renamed from FMODE_LINEBUF. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@7913 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ io.c | 13 +++++++------ rubyio.h | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4dd1fbbac9..c9ab5be542 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Mon Feb 7 23:14:11 2005 Tanaka Akira + + * io.c (io_getc): flush rb_stdout before read fro stdin, which is + connected to a tty. [ruby-core:4378] + + * rubyio.h (FMODE_TTY): renamed from FMODE_LINEBUF. + Mon Feb 7 02:13:05 2005 NAKAMURA Usaku * ext/socket/extconf.rb (sockaddr_storage): winsock2.h have the diff --git a/io.c b/io.c index fd7312270e..3331d7c6a9 100644 --- a/io.c +++ b/io.c @@ -485,7 +485,7 @@ io_fwrite(str, fptr) } if ((fptr->mode & FMODE_SYNC) || (fptr->wbuf && fptr->wbuf_capa <= fptr->wbuf_len + len) || - ((fptr->mode & FMODE_LINEBUF) && memchr(RSTRING(str)->ptr+offset, '\n', len))) { + ((fptr->mode & FMODE_TTY) && memchr(RSTRING(str)->ptr+offset, '\n', len))) { /* xxx: use writev to avoid double write if available */ if (fptr->wbuf_len && fptr->wbuf_len+len <= fptr->wbuf_capa) { if (fptr->wbuf_capa < fptr->wbuf_off+fptr->wbuf_len+len) { @@ -801,6 +801,9 @@ static int io_getc(OpenFile *fptr) { int r; + if (fptr->fd == 0 && (fptr->mode & FMODE_TTY)) { + rb_io_flush(rb_stdout); + } if (fptr->rbuf == NULL) { fptr->rbuf_off = 0; fptr->rbuf_len = 0; @@ -2643,8 +2646,8 @@ rb_fdopen(fd, mode) static void io_check_tty(OpenFile *fptr) { - if ((fptr->mode & FMODE_WRITABLE) && isatty(fptr->fd)) - fptr->mode |= FMODE_LINEBUF|FMODE_DUPLEX; + if (isatty(fptr->fd)) + fptr->mode |= FMODE_TTY|FMODE_DUPLEX; } static VALUE @@ -3938,9 +3941,7 @@ prep_io(fd, mode, klass, path) } #endif fp->mode = mode; - if (fp->mode & FMODE_WRITABLE) { - io_check_tty(fp); - } + io_check_tty(fp); if (path) fp->path = strdup(path); return io; diff --git a/rubyio.h b/rubyio.h index 7c6973f8e4..f52db7f21c 100644 --- a/rubyio.h +++ b/rubyio.h @@ -46,7 +46,7 @@ typedef struct OpenFile { #define FMODE_CREATE 128 #define FMODE_BINMODE 4 #define FMODE_SYNC 8 -#define FMODE_LINEBUF 16 +#define FMODE_TTY 16 #define FMODE_DUPLEX 32 #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)