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

* 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

38
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;
@ -333,9 +333,8 @@ rb_io_flush(io)
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
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;
} }
@ -484,9 +483,8 @@ rb_io_fsync(io)
GetOpenFile(io, fptr); GetOpenFile(io, fptr);
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);
@ -1477,7 +1475,7 @@ rb_io_binmode_flags(mode)
int flags; int flags;
switch (mode & (O_RDONLY|O_WRONLY|O_RDWR)) { switch (mode & (O_RDONLY|O_WRONLY|O_RDWR)) {
case O_RDONLY: case O_RDONLY:
flags = FMODE_READABLE; flags = FMODE_READABLE;
break; break;
case O_WRONLY: case O_WRONLY:
@ -1543,7 +1541,7 @@ rb_io_binmode_mode(flags, mode)
char *p = mode; char *p = mode;
switch (flags & (O_RDONLY|O_WRONLY|O_RDWR)) { switch (flags & (O_RDONLY|O_WRONLY|O_RDWR)) {
case O_RDONLY: case O_RDONLY:
*p++ = 'r'; *p++ = 'r';
break; break;
case O_WRONLY: case O_WRONLY:
@ -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;
@ -2593,7 +2587,7 @@ rb_io_s_alloc(klass)
{ {
NEWOBJ(io, struct RFile); NEWOBJ(io, struct RFile);
OBJSETUP(io, klass, T_FILE); OBJSETUP(io, klass, T_FILE);
io->fptr = 0; io->fptr = 0;
return (VALUE)io; return (VALUE)io;