summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-24 22:53:51 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-24 22:53:51 +0000
commiteec0b2d88a68d7931ff1d41c5cc2c773f7f22c6c (patch)
tree42449d482126683b6649ddf0eb58ce43484bb6e7 /io.c
parent85738261a582ceef498b86b784171fba59bf60cc (diff)
* dir.c (dir_inspect), io.c (rb_io_inspect): keep encoding of path.
[Bug #6072] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34795 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/io.c b/io.c
index 04868107d5..e7116cd824 100644
--- a/io.c
+++ b/io.c
@@ -1778,31 +1778,29 @@ static VALUE
rb_io_inspect(VALUE obj)
{
rb_io_t *fptr;
- const char *cname;
- char fd_desc[4+sizeof(int)*3];
- const char *path;
- const char *st = "";
+ VALUE result;
+ static const char closed[] = " (closed)";
fptr = RFILE(rb_io_taint_check(obj))->fptr;
if (!fptr) return rb_any_to_s(obj);
- cname = rb_obj_classname(obj);
+ result = rb_str_new_cstr("#<");
+ rb_str_append(result, rb_class_name(CLASS_OF(obj)));
+ rb_str_cat2(result, ":");
if (NIL_P(fptr->pathv)) {
if (fptr->fd < 0) {
- path = "";
- st = "(closed)";
+ rb_str_cat(result, closed+1, strlen(closed)-1);
}
else {
- snprintf(fd_desc, sizeof(fd_desc), "fd %d", fptr->fd);
- path = fd_desc;
+ rb_str_catf(result, "fd %d", fptr->fd);
}
}
else {
- path = RSTRING_PTR(fptr->pathv);
+ rb_str_append(result, fptr->pathv);
if (fptr->fd < 0) {
- st = " (closed)";
+ rb_str_cat(result, closed, strlen(closed));
}
}
- return rb_sprintf("#<%s:%s%s>", cname, path, st);
+ return rb_str_cat2(result, ">");
}
/*