diff options
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -1048,16 +1048,23 @@ syserr_initialize(int argc, VALUE *argv, VALUE self) if (!NIL_P(error)) err = strerror(NUM2INT(error)); else err = "unknown error"; if (!NIL_P(mesg)) { + rb_encoding *le = rb_locale_encoding(); VALUE str = mesg; StringValue(str); mesg = rb_sprintf("%s - %.*s", err, (int)RSTRING_LEN(str), RSTRING_PTR(str)); + if (le == rb_usascii_encoding()) { + rb_encoding *me = rb_enc_get(mesg); + if (le != me && rb_enc_asciicompat(me)) + le = me; + }/* else assume err is non ASCII string. */ + rb_enc_associate(mesg, le); } else { mesg = rb_str_new2(err); + rb_enc_associate(mesg, rb_locale_encoding()); } - rb_enc_associate(mesg, rb_locale_encoding()); rb_call_super(1, &mesg); rb_iv_set(self, "errno", error); return self; |