summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--ext/socket/socket.c2
-rw-r--r--io.c28
-rw-r--r--rubyio.h2
4 files changed, 24 insertions, 15 deletions
diff --git a/ChangeLog b/ChangeLog
index 2602fb0eb1..e7b893d056 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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 ac2cac8809..2ffa84b296 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;
}
diff --git a/io.c b/io.c
index e2547bc544..d92d548998 100644
--- a/io.c
+++ b/io.c
@@ -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");
diff --git a/rubyio.h b/rubyio.h
index e9716c0306..d9e734fa12 100644
--- a/rubyio.h
+++ b/rubyio.h
@@ -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)