aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-12-19 06:25:05 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-12-19 06:25:05 +0000
commit4c924ab14a032a6fcb695059463ee1cd7734b77a (patch)
tree23e2cce683cc020ec16c18b651f83bffd90352ec
parentterm: remove TODO (diff)
main: verify locale is UTF-8
-rw-r--r--main.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/main.c b/main.c
index b9aa14d3..a8776606 100644
--- a/main.c
+++ b/main.c
@@ -47,6 +47,21 @@ print_usage(const char *prog_name)
" -v,--version show the version number and quit\n");
}
+bool
+locale_is_utf8(void)
+{
+ assert(strlen(u8"ö") == 2);
+
+ wchar_t w;
+ if (mbtowc(&w, u8"ö", 2) != 2)
+ return false;
+
+ if (w != U'ö')
+ return false;
+
+ return true;
+}
+
struct shutdown_context {
struct terminal **term;
int exit_code;
@@ -167,12 +182,16 @@ main(int argc, char *const *argv)
argc -= optind;
argv += optind;
- setlocale(LC_ALL, "");
-
struct config conf = {NULL};
if (!config_load(&conf, conf_path))
return ret;
+ setlocale(LC_ALL, "");
+ if (!locale_is_utf8()) {
+ LOG_ERR("locale is not UTF-8");
+ return ret;
+ }
+
if (conf_term != NULL) {
free(conf.term);
conf.term = strdup(conf_term);
@@ -242,6 +261,8 @@ out:
fdm_destroy(fdm);
config_free(conf);
+
+ LOG_INFO("goodbye");
log_deinit();
return ret == EXIT_SUCCESS && !as_server ? shutdown_ctx.exit_code : ret;
}