summaryrefslogtreecommitdiff
path: root/ext/stringio/stringio.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/stringio/stringio.c')
-rw-r--r--ext/stringio/stringio.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index db3732e072..e964e79e12 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -1233,17 +1233,17 @@ static VALUE
strio_putc(VALUE self, VALUE ch)
{
struct StringIO *ptr = writable(self);
- int c = NUM2CHR(ch);
- long olen;
+ VALUE str;
check_modifiable(ptr);
- olen = RSTRING_LEN(ptr->string);
- if (ptr->flags & FMODE_APPEND) {
- ptr->pos = olen;
+ if (RB_TYPE_P(ch, T_STRING)) {
+ str = rb_str_substr(ch, 0, 1);
}
- strio_extend(ptr, ptr->pos, 1);
- RSTRING_PTR(ptr->string)[ptr->pos++] = c;
- OBJ_INFECT(ptr->string, self);
+ else {
+ char c = NUM2CHR(ch);
+ str = rb_str_new(&c, 1);
+ }
+ strio_write(self, str);
return ch;
}