From 778a496caa308017a9381f8f38150aa0d9f71d25 Mon Sep 17 00:00:00 2001 From: Charles Wilson Date: Fri, 20 Mar 2009 03:14:49 -0400 Subject: [PATCH] Issue 15, part 12. wchar_t is only 16 bits Check the size in configure.ac/CMakeLists.txt, and react as needed in libarchive/archive_string.c. SVN-Revision: 819 --- CMakeLists.txt | 2 ++ configure.ac | 5 +++++ libarchive/archive_string.c | 10 ++++++++++ 3 files changed, 17 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 96bbac72a..59b5a94c5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -467,6 +467,8 @@ IF(NOT HAVE_UINTMAX_T) ENDIF(MSVC) ENDIF(NOT HAVE_UINTMAX_T) # +CHECK_TYPE_SIZE(wchar_t SIZEOF_WCHAR_T) +# # Check if _FILE_OFFSET_BITS macro needed for large files # CHECK_FILE_OFFSET_BITS() diff --git a/configure.ac b/configure.ac index c2fa7f83d..cd4988010 100644 --- a/configure.ac +++ b/configure.ac @@ -318,6 +318,11 @@ AC_CHECK_DECL([EILSEQ], [AC_DEFINE(HAVE_EILSEQ, 1, [A possible errno value for invalid file format errors])], [], [#include ]) +AC_CHECK_TYPE([wchar_t], + [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_[]wchar_t), 1, [Define to 1 if the system has the type `wchar_t'.])dnl + AC_CHECK_SIZEOF([wchar_t])], + []) + AC_HEADER_TIME # Checks for library functions. diff --git a/libarchive/archive_string.c b/libarchive/archive_string.c index eacfc08c1..e71c239f1 100644 --- a/libarchive/archive_string.c +++ b/libarchive/archive_string.c @@ -184,6 +184,7 @@ my_wctomb_utf8(char *p, wchar_t wc) p[1] = 0x80 | (wc & 0x3f); return (2); } +#if SIZEOF_WCHAR_T > 2 if (wc <= 0xffff) { p[0] = 0xe0 | ((wc >> 12) & 0x0f); p[1] = 0x80 | ((wc >> 6) & 0x3f); @@ -203,6 +204,15 @@ my_wctomb_utf8(char *p, wchar_t wc) * can actually fail. */ return (-1); +#else + /* is this the right thing to do when wchar_t is + * limited to 16 bits? + */ + p[0] = 0xe0 | ((wc >> 12) & 0x0f); + p[1] = 0x80 | ((wc >> 6) & 0x3f); + p[2] = 0x80 | (wc & 0x3f); + return (3); +#endif } static int