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.

This commit is contained in:
LoRd_MuldeR 2021-03-18 01:58:07 +01:00
parent 21cab67912
commit 2e74accf36
Signed by: mulder
GPG Key ID: 2B5913365F57E03F
2 changed files with 7 additions and 4 deletions

View File

@ -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 [[@][:]<passphrase>] <input.txt> <output.enc>\n"), program);
FPRINTF(stderr, T(" %") T(PRISTR) T(" --encrypt [[@][:]<passphrase>] <input.txt> <output.enc>\n"), program);
FPRINTF(stderr, T(" %") T(PRISTR) T(" --decrypt [[@][:]<passphrase>] <input.enc> <output.txt>\n"), program);
FPRINTF(stderr, T(" %") T(PRISTR) T(" --make-pw [<length>]\n\n"), program);
}

View File

@ -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
}