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

* io.c (io_write): flag when buffered write is done.

* io.c (fptr_finalize): do not raise error on EBADF if write
  buffer is empty.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2052 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2002-02-07 04:18:08 +00:00
parent 65806ccb72
commit 90991d9889
3 changed files with 32 additions and 4 deletions

View file

@ -1,3 +1,10 @@
Thu Feb 7 00:18:43 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_write): flag when buffered write is done.
* io.c (fptr_finalize): do not raise error on EBADF if write
buffer is empty.
Wed Feb 6 17:18:54 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp> Wed Feb 6 17:18:54 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* configure.in: keep old config.h unless changed. * configure.in: keep old config.h unless changed.

28
io.c
View file

@ -268,6 +268,10 @@ io_write(io, str)
#endif #endif
if (fptr->mode & FMODE_SYNC) { if (fptr->mode & FMODE_SYNC) {
io_fflush(f, fptr->path); io_fflush(f, fptr->path);
fptr->mode &= ~FMODE_WBUF;
}
else {
fptr->mode |= FMODE_WBUF;
} }
return INT2FIX(n); return INT2FIX(n);
@ -300,6 +304,7 @@ rb_io_flush(io)
f = GetWriteFile(fptr); f = GetWriteFile(fptr);
io_fflush(f, fptr->path); io_fflush(f, fptr->path);
fptr->mode &= ~FMODE_WBUF;
return io; return io;
} }
@ -451,6 +456,7 @@ rb_io_fsync(io)
f = GetWriteFile(fptr); f = GetWriteFile(fptr);
io_fflush(f, fptr->path); io_fflush(f, fptr->path);
fptr->mode &= ~FMODE_WBUF;
if (fsync(fileno(f)) < 0) if (fsync(fileno(f)) < 0)
rb_sys_fail(fptr->path); rb_sys_fail(fptr->path);
return INT2FIX(0); return INT2FIX(0);
@ -1103,13 +1109,18 @@ fptr_finalize(fptr, fin)
if (fptr->f2) { if (fptr->f2) {
f2 = fileno(fptr->f2); f2 = fileno(fptr->f2);
n2 = fclose(fptr->f2); n2 = fclose(fptr->f2);
fptr->f2 = 0;
if (n2 < 0) e = errno; if (n2 < 0) e = errno;
} }
if (fptr->f && fptr->f != fptr->f2) { if (fptr->f) {
f1 = fileno(fptr->f); f1 = fileno(fptr->f);
n1 = fclose(fptr->f); n1 = fclose(fptr->f);
if (n1 < 0 && (e = errno) == EBADF && f1 == f2) fptr->f = 0;
n1 = 0; if (n1 < 0 && errno == EBADF) {
if (f1 == f2 || !(fptr->mode & FMODE_WBUF)) {
n1 = 0;
}
}
} }
if (!fin && (n1 < 0 || n2 < 0)) { if (!fin && (n1 < 0 || n2 < 0)) {
if (n1 == 0) errno = e; if (n1 == 0) errno = e;
@ -1128,7 +1139,6 @@ rb_io_fptr_cleanup(fptr, fin)
else { else {
fptr_finalize(fptr, fin); fptr_finalize(fptr, fin);
} }
fptr->f = fptr->f2 = 0;
if (fptr->path) { if (fptr->path) {
free(fptr->path); free(fptr->path);
@ -1259,6 +1269,9 @@ rb_io_syswrite(io, str)
rb_io_check_writable(fptr); rb_io_check_writable(fptr);
f = GetWriteFile(fptr); f = GetWriteFile(fptr);
if (fptr->mode & FMODE_WBUF) {
rb_warn("syswrite for buffered IO");
}
if (!rb_thread_fd_writable(fileno(f))) { if (!rb_thread_fd_writable(fileno(f))) {
rb_io_check_closed(fptr); rb_io_check_closed(fptr);
} }
@ -1975,6 +1988,7 @@ io_reopen(io, nfile)
else if (orig->mode & FMODE_WRITABLE) { else if (orig->mode & FMODE_WRITABLE) {
io_fflush(orig->f, orig->path); io_fflush(orig->f, orig->path);
} }
orig->mode &= ~FMODE_WBUF;
rb_thread_fd_close(fileno(fptr->f)); rb_thread_fd_close(fileno(fptr->f));
/* copy OpenFile structure */ /* copy OpenFile structure */
@ -2104,6 +2118,7 @@ rb_io_clone(io)
else if (orig->mode & FMODE_WRITABLE) { else if (orig->mode & FMODE_WRITABLE) {
io_fflush(orig->f, orig->path); io_fflush(orig->f, orig->path);
} }
orig->mode &= ~FMODE_WBUF;
/* copy OpenFile structure */ /* copy OpenFile structure */
fptr->mode = orig->mode; fptr->mode = orig->mode;
@ -2228,8 +2243,13 @@ rb_io_putc(io, ch)
if (fputc(c, f) == EOF) if (fputc(c, f) == EOF)
rb_sys_fail(fptr->path); rb_sys_fail(fptr->path);
fptr->mode |= FMODE_WBUF;
if (fptr->mode & FMODE_SYNC) { if (fptr->mode & FMODE_SYNC) {
io_fflush(f, fptr->path); io_fflush(f, fptr->path);
fptr->mode &= ~FMODE_WBUF;
}
else {
fptr->mode |= FMODE_WBUF;
} }
return ch; return ch;

View file

@ -31,6 +31,7 @@ typedef struct OpenFile {
#define FMODE_READWRITE 3 #define FMODE_READWRITE 3
#define FMODE_BINMODE 4 #define FMODE_BINMODE 4
#define FMODE_SYNC 8 #define FMODE_SYNC 8
#define FMODE_WBUF 16
#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr) #define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr)