From: Tanaka Akira Date: 2008-02-07T14:13:29+09:00 Subject: Re: reopen: can't change access mode from "w+" to "w"? In article <20080206043831.7F10DE067F@mail.bc9.jp>, Nobuyoshi Nakada writes: > Here, the mode of STDOUT was changed to "w+" by previos reopen, > and this is trying to change the mode to "w" back, or "shrink" > in other words. This patch makes the first reopen doesn't change to "w+". Index: io.c =================================================================== --- io.c (revision 15392) +++ io.c (working copy) @@ -4132,7 +4132,13 @@ io_reopen(VALUE io, VALUE nfile) } /* copy rb_io_t structure */ - fptr->mode = orig->mode | (fptr->mode & FMODE_PREP); + if (fptr->mode & FMODE_PREP) { + int mask = FMODE_PREP|FMODE_READWRITE; + fptr->mode = (orig->mode & ~mask)|(fptr->mode & mask); + } + else { + fptr->mode = orig->mode; + } fptr->pid = orig->pid; fptr->lineno = orig->lineno; if (fptr->path) free(fptr->path); -- Tanaka Akira