From c93bf465dddd8d3aa8ffd10b1c13e8d1c9ded38b Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 6 Nov 2005 14:41:53 +0000 Subject: * ext/iconv/iconv.c (Iconv::BrokenLibrary): exception when detected a bug of underlying library. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@9509 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/iconv/iconv.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'ext/iconv/iconv.c') diff --git a/ext/iconv/iconv.c b/ext/iconv/iconv.c index 5715b8fbde..98bef9610c 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)); @@ -248,7 +249,10 @@ iconv_try #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; @@ -260,6 +264,8 @@ iconv_try return rb_eIconvIllegalSeq; case EINVAL: return rb_eIconvInvalidChar; + case 0: + return rb_eIconvBrokenLibrary; default: rb_sys_fail("iconv"); } @@ -857,6 +863,13 @@ iconv_failure_inspect * 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)) { @@ -880,10 +893,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"); -- cgit v1.2.3