From 2e74accf36588e47c9d9f703291a1916c049a3d7 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Thu, 18 Mar 2021 01:58:07 +0100 Subject: [PATCH] Don't set 'stdout' to _O_BINARY mode on Windows, because it can have some weird effect when printing text to the terminal. Also, we currently don't output any "binary" data to 'stdout' anyway. --- frontend/src/main.c | 2 +- frontend/src/utils.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/src/main.c b/frontend/src/main.c index f207706..469d661 100644 --- a/frontend/src/main.c +++ b/frontend/src/main.c @@ -93,7 +93,7 @@ static void print_manpage(const CHR *const program) FPUTS(T("https://creativecommons.org/publicdomain/zero/1.0/legalcode\n"), stderr); FPUTS(T("====================================================================\n\n"), stderr); FPUTS(T("Usage:\n"), stderr); - FPRINTF(stderr, T(" %") T(PRISTR) T(" --encrypt [[@][:]] \n"), program); + FPRINTF(stderr, T(" %") T(PRISTR) T(" --encrypt [[@][:]] \n"), program); FPRINTF(stderr, T(" %") T(PRISTR) T(" --decrypt [[@][:]] \n"), program); FPRINTF(stderr, T(" %") T(PRISTR) T(" --make-pw []\n\n"), program); } diff --git a/frontend/src/utils.c b/frontend/src/utils.c index 0c435f3..827ff5c 100644 --- a/frontend/src/utils.c +++ b/frontend/src/utils.c @@ -71,15 +71,18 @@ static void clear_cmdline_args(char *const acmdln, wchar_t *const wcmdln) if (len > 5U) wcscpy(wcmdln, L"slunk"); } } +static void set_translation_mode(FILE* const stream, const int utf8_mode) +{ + _setmode(_fileno(stream), utf8_mode ? _O_U8TEXT : _O_BINARY); +} #endif void init_terminal(void) { #ifdef _WIN32 SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); - _setmode(_fileno(stdout), _O_BINARY); - _setmode(_fileno(stdin), _O_BINARY); - _setmode(_fileno(stderr), _O_U8TEXT); + set_translation_mode(stderr, 1); + set_translation_mode(stdin, 0); clear_cmdline_args(_acmdln, _wcmdln); #endif }