summaryrefslogtreecommitdiffstats
path: root/ext/iconv
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-06 14:41:53 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-11-06 14:41:53 +0000
commitfb0f26ab9e7faf70df0cd82d508fdf079f0cdad5 (patch)
tree42cb3d501c55fe02d5130893773486a9f55f9c04 /ext/iconv
parent0a31eed4444284bd1aa3294cb9d676ef2e6eb631 (diff)
downloadruby-fb0f26ab9e7faf70df0cd82d508fdf079f0cdad5.tar.gz
ruby-fb0f26ab9e7faf70df0cd82d508fdf079f0cdad5.tar.xz
ruby-fb0f26ab9e7faf70df0cd82d508fdf079f0cdad5.zip
* ext/iconv/iconv.c (Iconv::BrokenLibrary): exception when detected a
bug of underlying library. git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@9509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/iconv')
-rw-r--r--ext/iconv/iconv.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c
index 5e178f45c..b75d1a659 100644
--- a/ext/iconv/iconv.c
+++ b/ext/iconv/iconv.c
@@ -88,6 +88,7 @@ static VALUE rb_eIconvFailure;
static VALUE rb_eIconvIllegalSeq;
static VALUE rb_eIconvInvalidChar;
static VALUE rb_eIconvOutOfRange;
+static VALUE rb_eIconvBrokenLibrary;
static ID rb_success, rb_failed;
static VALUE iconv_fail _((VALUE error, VALUE success, VALUE failed, struct iconv_env_t* env, const char *mesg));
@@ -207,7 +208,10 @@ iconv_try(iconv_t cd, const char **inptr, size_t *inlen, char **outptr, size_t *
#else
#define ICONV_INPTR_CAST (char **)
#endif
- size_t ret = iconv(cd, ICONV_INPTR_CAST inptr, inlen, outptr, outlen);
+ size_t ret;
+
+ errno = 0;
+ ret = iconv(cd, ICONV_INPTR_CAST inptr, inlen, outptr, outlen);
if (ret == (size_t)-1) {
if (!*inlen)
return Qfalse;
@@ -219,6 +223,8 @@ iconv_try(iconv_t cd, const char **inptr, size_t *inlen, char **outptr, size_t *
return rb_eIconvIllegalSeq;
case EINVAL:
return rb_eIconvInvalidChar;
+ case 0:
+ return rb_eIconvBrokenLibrary;
default:
rb_sys_fail("iconv");
}
@@ -768,6 +774,13 @@ iconv_failure_inspect(VALUE self)
* Iconv library internal error. Must not occur.
*/
+/*
+ * Document-class: Iconv::BrokenLibrary
+ *
+ * Detected a bug of underlying iconv(3) libray.
+ * * returns an error without setting errno properly
+ */
+
void
Init_iconv(void)
{
@@ -792,10 +805,12 @@ Init_iconv(void)
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);
+ rb_eIconvBrokenLibrary = rb_define_class_under(rb_cIconv, "BrokenLibrary", rb_eRuntimeError);
rb_include_module(rb_eIconvInvalidEncoding, rb_eIconvFailure);
rb_include_module(rb_eIconvIllegalSeq, rb_eIconvFailure);
rb_include_module(rb_eIconvInvalidChar, rb_eIconvFailure);
rb_include_module(rb_eIconvOutOfRange, rb_eIconvFailure);
+ rb_include_module(rb_eIconvBrokenLibrary, rb_eIconvFailure);
rb_success = rb_intern("success");
rb_failed = rb_intern("failed");