t_setutf8 helper
authorSzabolcs Nagy <nsz@port70.net>
Thu, 22 Jun 2017 23:40:47 +0000 (23:40 +0000)
committerSzabolcs Nagy <nsz@port70.net>
Thu, 22 Jun 2017 23:40:47 +0000 (23:40 +0000)
src/common/utf8.c [new file with mode: 0644]

diff --git a/src/common/utf8.c b/src/common/utf8.c
new file mode 100644 (file)
index 0000000..a184991
--- /dev/null
@@ -0,0 +1,21 @@
+#include <locale.h>
+#include <string.h>
+#include <langinfo.h>
+#include "test.h"
+
+int t_setutf8()
+{
+       (void)(
+       setlocale(LC_CTYPE, "C.UTF-8") ||
+       setlocale(LC_CTYPE, "POSIX.UTF-8") ||
+       setlocale(LC_CTYPE, "en_US.UTF-8") ||
+       setlocale(LC_CTYPE, "en_GB.UTF-8") ||
+       setlocale(LC_CTYPE, "en.UTF-8") ||
+       setlocale(LC_CTYPE, "UTF-8") ||
+       setlocale(LC_CTYPE, "") );
+       
+       if (strcmp(nl_langinfo(CODESET), "UTF-8"))
+               return t_error("cannot set UTF-8 locale for test (codeset=%s)\n", nl_langinfo(CODESET));
+
+       return 0;
+}