* io.c (io_fflush): DRY patch from /Christoph applied.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2308 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
matz 2002-03-29 14:50:09 +00:00
parent 76f963d077
commit 564222ba27
2 changed files with 20 additions and 22 deletions

View File

@ -20,6 +20,10 @@ Fri Mar 29 15:49:29 2002 Usaku Nakamura <usa@ruby-lang.org>
* win32/README.win32: follow recent changes. * win32/README.win32: follow recent changes.
Fri Mar 29 14:44:05 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* io.c (io_fflush): DRY patch from /Christoph applied.
Thu Mar 28 18:58:13 2002 Usaku Nakamura <usa@ruby-lang.org> Thu Mar 28 18:58:13 2002 Usaku Nakamura <usa@ruby-lang.org>
* win32/Makefile.sub (config.status): reflect user defined $CC in * win32/Makefile.sub (config.status): reflect user defined $CC in

28
io.c
View File

@ -244,9 +244,9 @@ ruby_dup(orig)
} }
static void static void
io_fflush(f, path) io_fflush(f, fptr)
FILE *f; FILE *f;
const char *path; OpenFile *fptr;
{ {
int n; int n;
@ -254,7 +254,7 @@ io_fflush(f, path)
TRAP_BEG; TRAP_BEG;
n = fflush(f); n = fflush(f);
TRAP_END; TRAP_END;
if (n == EOF) rb_sys_fail(path); if (n == EOF) rb_sys_fail(fptr->path);
fptr->mode &= ~FMODE_WBUF; fptr->mode &= ~FMODE_WBUF;
} }
@ -299,7 +299,7 @@ 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);
} }
else { else {
fptr->mode |= FMODE_WBUF; fptr->mode |= FMODE_WBUF;
@ -334,8 +334,7 @@ rb_io_flush(io)
rb_io_check_writable(fptr); rb_io_check_writable(fptr);
f = GetWriteFile(fptr); f = GetWriteFile(fptr);
io_fflush(f, fptr->path); io_fflush(f, fptr);
fptr->mode &= ~FMODE_WBUF;
return io; return io;
} }
@ -485,8 +484,7 @@ rb_io_fsync(io)
rb_io_check_writable(fptr); rb_io_check_writable(fptr);
f = GetWriteFile(fptr); f = GetWriteFile(fptr);
io_fflush(f, fptr->path); io_fflush(f, fptr);
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);
@ -2075,12 +2073,11 @@ io_reopen(io, nfile)
pos = ftello(orig->f); pos = ftello(orig->f);
} }
if (orig->f2) { if (orig->f2) {
io_fflush(orig->f2, orig->path); io_fflush(orig->f2, orig);
} }
else if (orig->mode & FMODE_WRITABLE) { else if (orig->mode & FMODE_WRITABLE) {
io_fflush(orig->f, orig->path); io_fflush(orig->f, orig);
} }
orig->mode &= ~FMODE_WBUF;
rb_thread_fd_close(fileno(fptr->f)); rb_thread_fd_close(fileno(fptr->f));
/* copy OpenFile structure */ /* copy OpenFile structure */
@ -2205,12 +2202,11 @@ rb_io_clone(io)
MakeOpenFile(clone, fptr); MakeOpenFile(clone, fptr);
if (orig->f2) { if (orig->f2) {
io_fflush(orig->f2, orig->path); io_fflush(orig->f2, orig);
} }
else if (orig->mode & FMODE_WRITABLE) { else if (orig->mode & FMODE_WRITABLE) {
io_fflush(orig->f, orig->path); io_fflush(orig->f, orig);
} }
orig->mode &= ~FMODE_WBUF;
/* copy OpenFile structure */ /* copy OpenFile structure */
fptr->mode = orig->mode; fptr->mode = orig->mode;
@ -2335,10 +2331,8 @@ 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);
fptr->mode &= ~FMODE_WBUF;
} }
else { else {
fptr->mode |= FMODE_WBUF; fptr->mode |= FMODE_WBUF;