summaryrefslogtreecommitdiff
path: root/error.c
diff options
context:
space:
mode:
Diffstat (limited to 'error.c')
-rw-r--r--error.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/error.c b/error.c
index f05600f7fb..94126f709b 100644
--- a/error.c
+++ b/error.c
@@ -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;