aboutsummaryrefslogtreecommitdiffstats
path: root/ext/iconv/iconv.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-18 14:59:49 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-01-18 14:59:49 +0000
commit91c798b670d3408db607dba74d782dc95982f23a (patch)
tree6e9b493d5fbab1c218edf03d2cdacf952266555e /ext/iconv/iconv.c
parenta7b1a2ecedb3d7180a164c045b90be4b2b38704d (diff)
downloadruby-91c798b670d3408db607dba74d782dc95982f23a.tar.gz
* ext/iconv/charset_alias.rb: prefer us_EN locale encodings or
former. [ruby-dev:22609] * ext/iconv/iconv.c (iconv_create): raise InvalidEncoding exception when EINVAL. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5493 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/iconv/iconv.c')
-rw-r--r--ext/iconv/iconv.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 4b1f4b5073..bceb7ca692 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -53,6 +53,7 @@ struct iconv_env_t
VALUE (*append)_((VALUE, VALUE));
};
+static VALUE rb_eIconvInvalidEncoding;
static VALUE rb_eIconvFailure;
static VALUE rb_eIconvIllegalSeq;
static VALUE rb_eIconvInvalidChar;
@@ -143,10 +144,15 @@ iconv_create
cd = iconv_open(tocode, fromcode);
}
if (cd == (iconv_t)-1) {
- volatile VALUE msg = rb_str_new2("iconv(\"");
+ int inval = errno == EINVAL;
+ volatile VALUE msg = rb_str_new2("iconv(\"" + (inval ? 5 : 0));
+ char *s;
+
rb_str_buf_cat2(rb_str_buf_append(msg, to), "\", \"");
rb_str_buf_cat2(rb_str_buf_append(msg, from), "\")");
- rb_sys_fail(StringValuePtr(msg));
+ s = StringValuePtr(msg);
+ if (!inval) rb_sys_fail(s);
+ rb_raise(rb_eIconvInvalidEncoding, "invalid encoding %s", s);
}
}
@@ -847,6 +853,7 @@ Init_iconv _((void))
rb_define_method(rb_eIconvFailure, "failed", iconv_failure_failed, 0);
rb_define_method(rb_eIconvFailure, "inspect", iconv_failure_inspect, 0);
+ rb_eIconvInvalidEncoding = rb_define_class_under(rb_cIconv, "InvalidEncoding", rb_eArgError);
rb_eIconvIllegalSeq = rb_define_class_under(rb_cIconv, "IllegalSequence", rb_eArgError);
rb_eIconvInvalidChar = rb_define_class_under(rb_cIconv, "InvalidCharacter", rb_eArgError);
rb_eIconvOutOfRange = rb_define_class_under(rb_cIconv, "OutOfRange", rb_eRuntimeError);