mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (io_reopen): check STDIN, STDOUT and STDERR mode according to
stdio streams. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15473 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a5c05a9ace
commit
433fbebfbc
3 changed files with 26 additions and 9 deletions
|
@ -1,3 +1,8 @@
|
|||
Thu Feb 14 21:00:14 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* io.c (io_reopen): check STDIN, STDOUT and STDERR mode according to
|
||||
stdio streams.
|
||||
|
||||
Thu Feb 14 16:07:40 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* test/ruby/test_math.rb: actual-expected argument ordering for
|
||||
|
|
|
@ -52,3 +52,20 @@ assert_equal 'ok', %q{
|
|||
File.unlink(tmpname)
|
||||
:ok
|
||||
}
|
||||
|
||||
assert_equal 'ok', %q{
|
||||
require 'tmpdir'
|
||||
begin
|
||||
tmpname = "#{Dir.tmpdir}/ruby-btest-#{$$}-#{rand(0x100000000).to_s(36)}"
|
||||
rw = File.open(tmpname, File::RDWR|File::CREAT|File::EXCL)
|
||||
rescue Errno::EEXIST
|
||||
retry
|
||||
end
|
||||
save = STDIN.dup
|
||||
STDIN.reopen(rw)
|
||||
STDIN.print "a"
|
||||
STDIN.reopen(save)
|
||||
rw.close
|
||||
File.unlink(tmpname)
|
||||
:ok
|
||||
}
|
||||
|
|
13
io.c
13
io.c
|
@ -4112,8 +4112,9 @@ io_reopen(VALUE io, VALUE nfile)
|
|||
if (fptr == orig) return io;
|
||||
#if !defined __CYGWIN__
|
||||
if (IS_PREP_STDIO(fptr)) {
|
||||
if (((fptr->mode & FMODE_READWRITE) & (orig->mode & FMODE_READWRITE)) !=
|
||||
(fptr->mode & FMODE_READWRITE)) {
|
||||
if ((fptr->stdio_file == stdin && !(orig->mode & FMODE_READABLE)) ||
|
||||
(fptr->stdio_file == stdout && !(orig->mode & FMODE_WRITABLE)) ||
|
||||
(fptr->stdio_file == stderr && !(orig->mode & FMODE_WRITABLE))) {
|
||||
rb_raise(rb_eArgError,
|
||||
"%s can't change access mode from \"%s\" to \"%s\"",
|
||||
PREP_STDIO_NAME(fptr), rb_io_flags_mode(fptr->mode),
|
||||
|
@ -4132,13 +4133,7 @@ io_reopen(VALUE io, VALUE nfile)
|
|||
}
|
||||
|
||||
/* copy rb_io_t structure */
|
||||
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->mode = orig->mode | (fptr->mode & FMODE_PREP);
|
||||
fptr->pid = orig->pid;
|
||||
fptr->lineno = orig->lineno;
|
||||
if (fptr->path) free(fptr->path);
|
||||
|
|
Loading…
Reference in a new issue