]> git.ipfire.org Git - thirdparty/libarchive.git/commitdiff
Fix string conversion errors on Mac OS X.
authorMichihiro NAKAJIMA <ggcueroad@gmail.com>
Wed, 25 May 2011 12:01:15 +0000 (08:01 -0400)
committerMichihiro NAKAJIMA <ggcueroad@gmail.com>
Wed, 25 May 2011 12:01:15 +0000 (08:01 -0400)
SVN-Revision: 3385

libarchive/archive_string.c

index d0736e14f9dfde227eacbfa31c6c0930e01e4549..53e2e568ae0c442165bb7a3cd3f76a6c09a94375 100644 (file)
@@ -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;
        }