From: Michihiro NAKAJIMA Date: Wed, 25 May 2011 12:01:15 +0000 (-0400) Subject: Fix string conversion errors on Mac OS X. X-Git-Tag: v3.0.0a~302 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f94dea8eeef655816d60ba3f9074052efa045a4e;p=thirdparty%2Flibarchive.git Fix string conversion errors on Mac OS X. SVN-Revision: 3385 --- diff --git a/libarchive/archive_string.c b/libarchive/archive_string.c index d0736e14f..53e2e568a 100644 --- a/libarchive/archive_string.c +++ b/libarchive/archive_string.c @@ -1090,6 +1090,12 @@ create_sconv_object(const char *fc, const char *tc, (flag & (SCONV_FROM_UTF8 | SCONV_FROM_UTF16BE))) { /* This case does not use iconv. */ sc->cd = (iconv_t)-1; +#if defined(__APPLE__) + } else if ((flag & SCONV_FROM_CHARSET) && (flag & SCONV_TO_UTF8)) { + sc->cd = iconv_open("UTF-8-MAC", fc); + if (sc->cd == (iconv_t)-1) + sc->cd = iconv_open(tc, fc); +#endif } else { sc->cd = iconv_open(tc, fc); } @@ -2414,6 +2420,12 @@ utf16be_to_unicode(uint32_t *pwc, const char *s, size_t n) return (utf16_to_unicode(pwc, s, n, 1)); } +static int +utf16le_to_unicode(uint32_t *pwc, const char *s, size_t n) +{ + return (utf16_to_unicode(pwc, s, n, 0)); +} + static int utf16_to_unicode(uint32_t *pwc, const char *s, size_t n, int be) { @@ -2627,6 +2639,9 @@ archive_string_append_unicode(struct archive_string *as, const char *s, if (sc->flag & SCONV_FROM_UTF16BE) { parse = utf16be_to_unicode; tm = 1; + } else if (sc->flag & SCONV_FROM_UTF16LE) { + parse = utf16le_to_unicode; + tm = 1; } else { parse = cesu8_to_unicode; tm = ts; @@ -2840,6 +2855,10 @@ archive_string_normalize_C(struct archive_string *as, const char *s, parse = utf16be_to_unicode; tm = 1; spair = 4;/* surrogate pair size in UTF-16. */ + } else if (sc->flag & SCONV_FROM_UTF16LE) { + parse = utf16le_to_unicode; + tm = 1; + spair = 4;/* surrogate pair size in UTF-16. */ } else { parse = cesu8_to_unicode; tm = ts; @@ -3134,6 +3153,8 @@ archive_string_normalize_D(struct archive_string *as, const char *s, */ if (sc->flag & SCONV_FROM_UTF16BE) sc->flag |= SCONV_TO_UTF16BE; + else if (sc->flag & SCONV_FROM_UTF16LE) + sc->flag |= SCONV_TO_UTF16LE; else sc->flag |= SCONV_TO_UTF8; }