From: Michihiro NAKAJIMA Date: Sun, 29 May 2011 13:32:23 +0000 (-0400) Subject: For Mac OS X, update comment in create_sconv_object(), and perform the normalization... X-Git-Tag: v3.0.0a~298 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94be54ed6fadacd52c7a221bb3423abaaa16df00;p=thirdparty%2Flibarchive.git For Mac OS X, update comment in create_sconv_object(), and perform the normalization form C when current locale is not UTF-8 because iconv would correctly handle filenames than those be in UTF-8 NFD or UTF-16BE in NFD. SVN-Revision: 3389 --- diff --git a/libarchive/archive_string.c b/libarchive/archive_string.c index 187a944b0..37897542e 100644 --- a/libarchive/archive_string.c +++ b/libarchive/archive_string.c @@ -1042,46 +1042,45 @@ create_sconv_object(const char *fc, const char *tc, */ if (strcmp(tc, "UTF-8") == 0) flag |= SCONV_TO_UTF8; + else if (strcmp(tc, "UTF-16BE") == 0) + flag |= SCONV_TO_UTF16BE; if (strcmp(fc, "UTF-8") == 0) flag |= SCONV_FROM_UTF8; - if (strcmp(tc, "UTF-16BE") == 0) - flag |= SCONV_TO_UTF16BE; - if (strcmp(fc, "UTF-16BE") == 0) + else if (strcmp(fc, "UTF-16BE") == 0) flag |= SCONV_FROM_UTF16BE; #if defined(_WIN32) && !defined(__CYGWIN__) if (sc->to_cp == CP_UTF8) flag |= SCONV_TO_UTF8; + else if (sc->to_cp == CP_UTF16BE) + flag |= SCONV_TO_UTF16BE; if (sc->from_cp == CP_UTF8) flag |= SCONV_FROM_UTF8; - if (sc->to_cp == CP_UTF16BE) - flag |= SCONV_TO_UTF16BE; - if (sc->from_cp == CP_UTF16BE) + else if (sc->from_cp == CP_UTF16BE) flag |= SCONV_FROM_UTF16BE; #endif /* - * Set a flag for UTF-8 NFD. Usually iconv cannot handle - * UTF-8 NFD. So we have to translate UTF-8 NFD characters - * to NFC ones ourselves so that to prevent that the same - * sight of two filenames, one is NFC and other is NFD, - * would be in its directory. + * Set a flag for Unicode NFD. Usually iconv cannot correctly + * handle it. So we have to translate NFD characters to NFC ones + * ourselves before iconv handles. Another reason is to prevent + * that the same sight of two filenames, one is NFC and other + * is NFD, would be in its directory. + * On Mac OS X, although its filesystem layer automatically + * convert filenames to NFD, it would be useful for filename + * comparing to find out the same filenames that we normalize + * that to be NFD ourselves. */ if ((flag & SCONV_FROM_CHARSET) && (flag & (SCONV_FROM_UTF16BE | SCONV_FROM_UTF8))) { #if defined(__APPLE__) - flag |= SCONV_NORMALIZATION_D; -#else - flag |= SCONV_NORMALIZATION_C; + if (flag & SCONV_TO_UTF8) { + if (createUniInfo(sc) == 0) + flag |= SCONV_NORMALIZATION_D; + } else #endif + flag |= SCONV_NORMALIZATION_C; } -#if defined(__APPLE__) - if (flag & SCONV_NORMALIZATION_D) { - if (createUniInfo(sc) != 0) - flag &= ~SCONV_NORMALIZATION_D; - } -#endif - #if defined(HAVE_ICONV) /* * Create an iconv object. @@ -1092,9 +1091,23 @@ create_sconv_object(const char *fc, const char *tc, sc->cd = (iconv_t)-1; #if defined(__APPLE__) } else if ((flag & SCONV_FROM_CHARSET) && (flag & SCONV_TO_UTF8)) { + /* + * In case reading an archive file. + * Translate non-Unicode filenames in an archive file to + * UTF-8-MAC filenames. + */ sc->cd = iconv_open("UTF-8-MAC", fc); if (sc->cd == (iconv_t)-1) sc->cd = iconv_open(tc, fc); + } else if ((flag & SCONV_TO_CHARSET) && (flag & SCONV_FROM_UTF8)) { + /* + * In case writing an archive file. + * Translate UTF-8-MAC filenames in HFS Plus to non-Unicode + * filenames. + */ + sc->cd = iconv_open(to, "UTF-8-MAC"); + if (sc->cd == (iconv_t)-1) + sc->cd = iconv_open(tc, fc); #endif } else { sc->cd = iconv_open(tc, fc);