mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* io.c (rb_io_inspect): show fd number if there is no pathname.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@20940 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
81031ebdcc
commit
fbcc23a8fa
3 changed files with 23 additions and 5 deletions
|
@ -1,3 +1,7 @@
|
|||
Tue Dec 23 16:22:41 2008 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* io.c (rb_io_inspect): show fd number if there is no pathname.
|
||||
|
||||
Tue Dec 23 15:48:55 2008 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||
|
||||
* tool/file2lastrev.rb: shouldn't use single quote in shell's command
|
||||
|
|
22
io.c
22
io.c
|
@ -1353,15 +1353,29 @@ rb_io_inspect(VALUE obj)
|
|||
{
|
||||
rb_io_t *fptr;
|
||||
const char *cname;
|
||||
char fd_desc[256];
|
||||
const char *path;
|
||||
const char *st = "";
|
||||
|
||||
fptr = RFILE(rb_io_taint_check(obj))->fptr;
|
||||
if (!fptr || NIL_P(fptr->pathv)) return rb_any_to_s(obj);
|
||||
cname = rb_obj_classname(obj);
|
||||
if (fptr->fd < 0) {
|
||||
st = " (closed)";
|
||||
if (!fptr || NIL_P(fptr->pathv)) {
|
||||
if (fptr->fd < 0) {
|
||||
path = "";
|
||||
st = "(closed)";
|
||||
}
|
||||
else {
|
||||
snprintf(fd_desc, sizeof(fd_desc), "fd %d", fptr->fd);
|
||||
path = fd_desc;
|
||||
}
|
||||
}
|
||||
return rb_sprintf("#<%s:%s%s>", cname, RSTRING_PTR(fptr->pathv), st);
|
||||
else {
|
||||
path = RSTRING_PTR(fptr->pathv);
|
||||
if (fptr->fd < 0) {
|
||||
st = " (closed)";
|
||||
}
|
||||
}
|
||||
return rb_sprintf("#<%s:%s%s>", cname, path, st);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -705,7 +705,7 @@ class TestIO < Test::Unit::TestCase
|
|||
|
||||
def test_inspect
|
||||
with_pipe do |r, w|
|
||||
assert(r.inspect =~ /^#<IO:0x[0-9a-f]+>$/)
|
||||
assert(r.inspect =~ /^#<IO:fd \d+>$/)
|
||||
assert_raise(SecurityError) do
|
||||
safe_4 { r.inspect }
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue