mbsrtowcs for thread safe if available.
SVN-Revision: 3075
CHECK_FUNCTION_EXISTS_GLIBC(lstat HAVE_LSTAT)
CHECK_FUNCTION_EXISTS_GLIBC(lutimes HAVE_LUTIMES)
CHECK_FUNCTION_EXISTS_GLIBC(mbrtowc HAVE_MBRTOWC)
+CHECK_FUNCTION_EXISTS_GLIBC(mbsnrtowcs HAVE_MBSNRTOWCS)
+CHECK_FUNCTION_EXISTS_GLIBC(mbsrtowcs HAVE_MBSRTOWCS)
CHECK_FUNCTION_EXISTS_GLIBC(memmove HAVE_MEMMOVE)
CHECK_FUNCTION_EXISTS_GLIBC(mkdir HAVE_MKDIR)
CHECK_FUNCTION_EXISTS_GLIBC(mkfifo HAVE_MKFIFO)
/* Define to 1 if you have the `mbrtowc' function. */
#cmakedefine HAVE_MBRTOWC 1
+/* Define to 1 if you have the `mbsnrtowcs' function. */
+#cmakedefine HAVE_MBSNRTOWCS 1
+
+/* Define to 1 if you have the `mbsrtowcs' function. */
+#cmakedefine HAVE_MBSRTOWCS 1
+
/* Define to 1 if you have the `memmove' function. */
#cmakedefine HAVE_MEMMOVE 1
AC_CHECK_FUNCS([fstat fstatat fstatfs fstatvfs ftruncate futimens futimes])
AC_CHECK_FUNCS([geteuid getpid getgrgid_r getgrnam_r])
AC_CHECK_FUNCS([getpwnam_r getpwuid_r getvfsbyname gmtime_r])
-AC_CHECK_FUNCS([lchflags lchmod lchown link localtime_r lstat])
-AC_CHECK_FUNCS([lutimes mbrtowc memmove memset mkdir mkfifo mknod mkstemp])
+AC_CHECK_FUNCS([lchflags lchmod lchown link localtime_r lstat lutimes])
+AC_CHECK_FUNCS([mbrtowc mbsnrtowcs mbsrtowcs memmove memset])
+AC_CHECK_FUNCS([mkdir mkfifo mknod mkstemp])
AC_CHECK_FUNCS([nl_langinfo openat pipe poll readlink readlinkat])
AC_CHECK_FUNCS([select setenv setlocale sigaction statfs statvfs])
AC_CHECK_FUNCS([strchr strdup strerror strncpy_s strrchr symlink timegm])
return (return_val);
}
-/*
- * UTF-8 ===> Unicode
- *
- */
-
/*
* Get the "current character set" name to use with iconv.
* On FreeBSD, the empty character set name "" chooses
* so this length estimate will always be big enough.
*/
size_t wcs_length = len;
+ const char *mbs = p;
+#if HAVE_MBSRTOWCS || HAVE_MBSNRTOWCS
+ mbstate_t shift_state;
+
+ memset(&shift_state, 0, sizeof(shift_state));
+#endif
if (NULL == archive_wstring_ensure(dest, dest->length + wcs_length + 1))
__archive_errx(1,
"No memory for archive_wstring_append_from_mbs()");
- r = mbstowcs(dest->s + dest->length, p, wcs_length);
+#if HAVE_MBSNRTOWCS
+ r = mbsnrtowcs(dest->s + dest->length, &mbs, len, wcs_length,
+ &shift_state);
+#elif HAVE_MBSRTOWCS
+ r = mbsrtowcs(dest->s + dest->length, &mbs, wcs_length, &shift_state);
+#else
+ r = mbstowcs(dest->s + dest->length, mbs, wcs_length);
+#endif
if (r != (size_t)-1) {
dest->length += r;
- dest->s[dest->length] = 0;
+ dest->s[dest->length] = L'\0';
return (0);
}
return (-1);