1/*
2 * LegacyClonk
3 *
4 * Copyright (c) 2024, The LegacyClonk Team and contributors
5 *
6 * Distributed under the terms of the ISC license; see accompanying file
7 * "COPYING" for details.
8 *
9 * "Clonk" is a registered trademark of Matthes Bender, used with permission.
10 * See accompanying file "TRADEMARK" for details.
11 *
12 * To redistribute this file separately, substitute the full license texts
13 * for the above references.
14 */
15
16#include "C4TextEncoding.h"
17
18#ifdef HAVE_ICONV
19#include <langinfo.h>
20#endif
21
22#ifdef HAVE_ICONV
23
24void C4TextEncodingConverter::CreateConverters(const char *const charsetCodeName)
25{
26 const char *systemCodeSet{nl_langinfo(CODESET)};
27 if (!systemCodeSet)
28 {
29 systemCodeSet = "ASCII";
30 }
31
32 const std::lock_guard lock{iconvMutex};
33 clonkToSystem = {iconv_open(tocode: systemCodeSet, fromcode: charsetCodeName)};
34 systemToClonk = {iconv_open(tocode: charsetCodeName, fromcode: systemCodeSet)};
35 clonkToUtf8 = {iconv_open(tocode: "UTF-8", fromcode: charsetCodeName)};
36 utf8ToClonk = {iconv_open(tocode: charsetCodeName, fromcode: "UTF-8")};
37}
38
39#endif
40
41C4TextEncodingConverter TextEncodingConverter;
42