diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-23 10:12:35 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-12-23 10:12:35 +0000 |
commit | 5bff150c4eba7f689b76012bea021e5253c3eb5d (patch) | |
tree | 4350800533845f058600f124774a4067cc705938 | |
parent | 1122cae3bf11d180b30d5d0fa41cfb124854a605 (diff) | |
download | ruby-5bff150c4eba7f689b76012bea021e5253c3eb5d.tar.gz ruby-5bff150c4eba7f689b76012bea021e5253c3eb5d.tar.xz ruby-5bff150c4eba7f689b76012bea021e5253c3eb5d.zip |
* rubyio.h: rename FMODE_UNSEEKABLE to FMODE_DUPLEX.
* io.c (io_check_tty): extracted function to set FMODE_LINEBUF and
FMODE_DUPLEX.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@7641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | ext/socket/socket.c | 2 | ||||
-rw-r--r-- | io.c | 28 | ||||
-rw-r--r-- | rubyio.h | 2 |
4 files changed, 24 insertions, 15 deletions
@@ -1,3 +1,10 @@ +Thu Dec 23 19:08:41 2004 Tanaka Akira <akr@m17n.org> + + * rubyio.h: rename FMODE_UNSEEKABLE to FMODE_DUPLEX. + + * io.c (io_check_tty): extracted function to set FMODE_LINEBUF and + FMODE_DUPLEX. + Thu Dec 23 13:13:33 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp> * ext/tcltklib/tcltklib.c: define TclTkLib::COMPILE_INFO and diff --git a/ext/socket/socket.c b/ext/socket/socket.c index ac2cac880..2ffa84b29 100644 --- a/ext/socket/socket.c +++ b/ext/socket/socket.c @@ -183,7 +183,7 @@ init_sock(sock, fd) MakeOpenFile(sock, fp); fp->fd = fd; - fp->mode = FMODE_READWRITE; + fp->mode = FMODE_READWRITE|FMODE_DUPLEX; if (do_not_reverse_lookup) { fp->mode |= FMODE_NOREVLOOKUP; } @@ -209,13 +209,13 @@ io_unread(OpenFile *fptr) { off_t r; rb_io_check_closed(fptr); - if (fptr->rbuf_len == 0 || fptr->mode & FMODE_UNSEEKABLE) + if (fptr->rbuf_len == 0 || fptr->mode & FMODE_DUPLEX) return; /* xxx: target position may be negative if buffer is filled by ungetc */ r = lseek(fptr->fd, -fptr->rbuf_len, SEEK_CUR); if (r < 0) { if (errno == ESPIPE) - fptr->mode |= FMODE_UNSEEKABLE; + fptr->mode |= FMODE_DUPLEX; return; } fptr->rbuf_off = 0; @@ -2555,7 +2555,7 @@ rb_fopen(fname, mode) rb_warn("setvbuf() can't be honoured for %s", fname); #endif #ifdef __human68k__ - fmode(file, _IOTEXT); + setmode(fileno(file), O_TEXT); #endif return file; } @@ -2601,6 +2601,13 @@ rb_fdopen(fd, mode) return file; } +static void +io_check_tty(OpenFile *fptr) +{ + if ((fptr->mode & FMODE_WRITABLE) && isatty(fptr->fd)) + fptr->mode |= FMODE_LINEBUF|FMODE_DUPLEX; +} + static VALUE rb_file_open_internal(io, fname, mode) VALUE io; @@ -2612,8 +2619,7 @@ rb_file_open_internal(io, fname, mode) fptr->mode = rb_io_mode_flags(mode); fptr->path = strdup(fname); fptr->fd = rb_sysopen(fptr->path, rb_io_mode_modenum(rb_io_flags_mode(fptr->mode)), 0666); - if ((fptr->mode & FMODE_WRITABLE) && isatty(fptr->fd)) - fptr->mode |= FMODE_LINEBUF; + io_check_tty(fptr); return io; } @@ -2638,8 +2644,7 @@ rb_file_sysopen_internal(io, fname, flags, mode) fptr->path = strdup(fname); fptr->mode = rb_io_modenum_flags(flags); fptr->fd = rb_sysopen(fptr->path, flags, mode); - if ((fptr->mode & FMODE_WRITABLE) && isatty(fptr->fd)) - fptr->mode |= FMODE_LINEBUF; + io_check_tty(fptr); return io; } @@ -2930,7 +2935,7 @@ pipe_open(argc, argv, mode) MakeOpenFile(port, fptr); fptr->fd = fd; fptr->stdio_file = fp; - fptr->mode = modef | FMODE_SYNC; + fptr->mode = modef | FMODE_SYNC|FMODE_DUPLEX; fptr->pid = pid; #if defined (__CYGWIN__) || !defined(HAVE_FORK) @@ -3883,9 +3888,7 @@ prep_stdio(f, mode, klass) if (fp->fd == 2) { /* stderr must be unbuffered */ fp->mode |= FMODE_SYNC; } - if (isatty(fp->fd)) { - fp->mode |= FMODE_LINEBUF; - } + io_check_tty(fp); } return io; @@ -3967,8 +3970,7 @@ rb_io_initialize(argc, argv, io) MakeOpenFile(io, fp); fp->fd = fd; fp->mode = rb_io_modenum_flags(flags); - if ((fp->mode & FMODE_WRITABLE) && isatty(fp->fd)) - fp->mode |= FMODE_LINEBUF; + io_check_tty(fp); } else if (RFILE(io)->fptr) { rb_raise(rb_eRuntimeError, "reinitializing IO"); @@ -47,7 +47,7 @@ typedef struct OpenFile { #define FMODE_BINMODE 4 #define FMODE_SYNC 8 #define FMODE_LINEBUF 16 -#define FMODE_UNSEEKABLE 32 +#define FMODE_DUPLEX 32 #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr) |