diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-12-19 06:25:05 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-12-19 06:25:05 +0000 |
| commit | 4c924ab14a032a6fcb695059463ee1cd7734b77a (patch) | |
| tree | 23e2cce683cc020ec16c18b651f83bffd90352ec | |
| parent | term: remove TODO (diff) | |
main: verify locale is UTF-8
| -rw-r--r-- | main.c | 25 |
1 files changed, 23 insertions, 2 deletions
@@ -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; } |
