X-Git-Url: https://wimlib.net/git/?p=wimlib;a=blobdiff_plain;f=src%2Fencoding.c;h=6a1148a8dea48deaadb258a620aa285e56a8b263;hp=8edf228817cba16e659ca47caed8d492e1de95cf;hb=5f3757249c17cb9e2826f645e0f8618534c80fcc;hpb=edf0f7f5331e626b55819dcafa88e202cdb82a32 diff --git a/src/encoding.c b/src/encoding.c index 8edf2288..6a1148a8 100644 --- a/src/encoding.c +++ b/src/encoding.c @@ -5,20 +5,18 @@ /* * Copyright (C) 2012, 2013 Eric Biggers * - * This file is part of wimlib, a library for working with WIM files. + * This file is free software; you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License as published by the Free + * Software Foundation; either version 3 of the License, or (at your option) any + * later version. * - * wimlib is free software; you can redistribute it and/or modify it under the - * terms of the GNU General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) - * any later version. - * - * wimlib is distributed in the hope that it will be useful, but WITHOUT ANY - * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR - * A PARTICULAR PURPOSE. See the GNU General Public License for more + * This file is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more * details. * - * You should have received a copy of the GNU General Public License - * along with wimlib; if not, see http://www.gnu.org/licenses/. + * You should have received a copy of the GNU Lesser General Public License + * along with this file; if not, see http://www.gnu.org/licenses/. */ #ifdef HAVE_CONFIG_H @@ -68,8 +66,6 @@ struct iconv_node { struct iconv_list_head name = { \ .from_encoding = from, \ .to_encoding = to, \ - .list = LIST_HEAD_INIT(name.list), \ - .mutex = PTHREAD_MUTEX_INITIALIZER, \ } static iconv_t * @@ -363,6 +359,13 @@ utf8_to_tstr_simple(const char *utf8str, tchar **out) return utf8_to_tstr(utf8str, strlen(utf8str), out, &out_nbytes); } +static void +iconv_init(struct iconv_list_head *head) +{ + pthread_mutex_init(&head->mutex, NULL); + INIT_LIST_HEAD(&head->list); +} + static void iconv_cleanup(struct iconv_list_head *head) { @@ -377,6 +380,19 @@ iconv_cleanup(struct iconv_list_head *head) } } +void +iconv_global_init(void) +{ + iconv_init(&iconv_utf8_to_tstr); + iconv_init(&iconv_tstr_to_utf8); +#if !TCHAR_IS_UTF16LE + iconv_init(&iconv_utf16le_to_tstr); + iconv_init(&iconv_tstr_to_utf16le); + iconv_init(&iconv_utf16le_to_utf8); + iconv_init(&iconv_utf8_to_utf16le); +#endif +} + void iconv_global_cleanup(void) { @@ -545,9 +561,11 @@ cmp_utf16le_strings(const utf16lechar *s1, size_t n1, return (n1 < n2) ? -1 : 1; } -/* Duplicate a UTF16-LE string which may not be null-terminated. */ +/* Duplicate a UTF16-LE string. The input string might not be null terminated + * and might be misaligned, but the returned string is guaranteed to be null + * terminated and properly aligned. */ utf16lechar * -utf16le_dupz(const utf16lechar *ustr, size_t usize) +utf16le_dupz(const void *ustr, size_t usize) { utf16lechar *dup = MALLOC(usize + sizeof(utf16lechar)); if (dup) {