aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-11-18 22:28:31 +0100
committerPřemysl Janouch <p.janouch@gmail.com>2014-11-18 22:30:19 +0100
commit64188f1fcf31f098956558fff536636bc01194b2 (patch)
tree7ef3d111be951d04c20767332960ad754d77fbd2
parentf1f9a00cda728eabd833e81e14cc7606bb34986a (diff)
downloadtermo-64188f1fcf31f098956558fff536636bc01194b2.tar.gz
termo-64188f1fcf31f098956558fff536636bc01194b2.tar.xz
termo-64188f1fcf31f098956558fff536636bc01194b2.zip
Revert "Don't bother with endianity"
It makes iconv() output the byte order mark first...
-rw-r--r--termo.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/termo.c b/termo.c
index a9addc4..063a5a7 100644
--- a/termo.c
+++ b/termo.c
@@ -330,9 +330,14 @@ termo_init (termo_t *tk, const char *term, const char *encoding)
if (!encoding)
encoding = nl_langinfo (CODESET);
- if ((tk->to_utf32_conv = iconv_open ("UTF-32", encoding)) == (iconv_t) -1)
+ // If we don't specify the endianity, iconv() outputs the BOM first
+ static const uint16_t endianity = 0x0102;
+ const char *utf32 = (*(uint8_t *) &endianity == 0x01)
+ ? "UTF-32BE" : "UTF-32LE";
+
+ if ((tk->to_utf32_conv = iconv_open (utf32, encoding)) == (iconv_t) -1)
return 0;
- if ((tk->from_utf32_conv = iconv_open (encoding, "UTF-32")) == (iconv_t) -1)
+ if ((tk->from_utf32_conv = iconv_open (encoding, utf32)) == (iconv_t) -1)
goto abort_free_to_utf32;
tk->buffer = malloc (tk->buffsize);