Commit 84717ec7d4074136fd55aa5edb18ae689e230d1a

Stefan Sperling 2018-09-02T13:30:31

add got_locale_is_utf8()

diff --git a/include/got_utf8.h b/include/got_utf8.h
index 2c3703e..50a99bc 100644
--- a/include/got_utf8.h
+++ b/include/got_utf8.h
@@ -15,3 +15,4 @@
  */
 
 const struct got_error *got_mbsavis(char**, int *, const char *);
+int got_locale_is_utf8(void);
diff --git a/lib/utf8.c b/lib/utf8.c
index d1db624..f1d5f2f 100644
--- a/lib/utf8.c
+++ b/lib/utf8.c
@@ -19,6 +19,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <wchar.h>
+#include <langinfo.h>
 
 #include "got_error.h"
 #include "got_utf8.h"
@@ -65,3 +66,10 @@ got_mbsavis(char** outp, int *widthp, const char *mbs)
 	*widthp = total_width;
 	return NULL;
 }
+
+int
+got_locale_is_utf8(void)
+{
+	char *codeset = nl_langinfo(CODESET);
+	return (strcmp(codeset, "UTF-8") == 0);
+}