-extern void
-iconv_global_cleanup(void);
-
-extern bool wimlib_mbs_is_utf8;
-
-#define DECLARE_CHAR_CONVERSION_FUNCTIONS(varname1, varname2, \
- chartype1, chartype2) \
- \
-extern int \
-varname1##_to_##varname2(const chartype1 *in, size_t in_nbytes, \
- chartype2 **out_ret, \
- size_t *out_nbytes_ret); \
- \
-extern int \
-varname1##_to_##varname2##_nbytes(const chartype1 *in, size_t in_nbytes,\
- size_t *out_nbytes_ret); \
- \
-extern int \
-varname1##_to_##varname2##_buf(const chartype1 *in, size_t in_nbytes, \
- chartype2 *out);
+/* String conversion functions */
+
+extern int
+utf8_to_utf16le(const char *in, size_t in_nbytes,
+ utf16lechar **out_ret, size_t *out_nbytes_ret);
+
+extern int
+utf16le_to_utf8(const utf16lechar *in, size_t in_nbytes,
+ char **out_ret, size_t *out_nbytes_ret);
+
+/* Identity conversion: duplicate a 'tchar' string. */
+static inline int
+tstr_to_tstr(const tchar *in, size_t in_nbytes,
+ tchar **out_ret, size_t *out_nbytes_ret)
+{
+ tchar *out = MALLOC(in_nbytes + sizeof(tchar));
+ if (unlikely(!out))
+ return WIMLIB_ERR_NOMEM;
+ memcpy(out, in, in_nbytes);
+ out[in_nbytes / sizeof(tchar)] = 0;
+ *out_ret = out;
+ if (out_nbytes_ret)
+ *out_nbytes_ret = in_nbytes;
+ return 0;
+}
+
+#if TCHAR_IS_UTF16LE
+
+/* tstr(UTF-16LE) <=> UTF-16LE */
+# define tstr_to_utf16le tstr_to_tstr
+# define utf16le_to_tstr tstr_to_tstr
+
+/* tstr(UTF-16LE) <=> UTF-8 */
+# define tstr_to_utf8 utf16le_to_utf8
+# define utf8_to_tstr utf8_to_utf16le
+
+#else
+
+/* tstr(UTF-8) <=> UTF-16LE */
+# define tstr_to_utf16le utf8_to_utf16le
+# define utf16le_to_tstr utf16le_to_utf8
+
+/* tstr(UTF-8) <=> UTF-8 */
+# define tstr_to_utf8 tstr_to_tstr
+# define utf8_to_tstr tstr_to_tstr
+
+#endif