Skip to content

Commit

Permalink
Issue 15, part 12. wchar_t is only 16 bits
Browse files Browse the repository at this point in the history
   Check the size in configure.ac/CMakeLists.txt,
   and react as needed in libarchive/archive_string.c.

SVN-Revision: 819
  • Loading branch information
cwilson1776 committed Mar 20, 2009
1 parent c6e7b27 commit 778a496
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Expand Up @@ -318,6 +318,11 @@ AC_CHECK_DECL([EILSEQ],
[AC_DEFINE(HAVE_EILSEQ, 1, [A possible errno value for invalid file format errors])],
[],
[#include <errno.h>])
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.
Expand Down
10 changes: 10 additions & 0 deletions libarchive/archive_string.c
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit 778a496

Please sign in to comment.