1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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: svn+ssh://ci.ruby-lang.org/ruby/trunk@7641 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2004-12-23 10:12:35 +00:00
parent 13fde676fe
commit 4ff1561a8c
4 changed files with 24 additions and 15 deletions

View file

@ -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

View file

@ -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;
}

28
io.c
View file

@ -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");

View file

@ -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)