From f7c4b6ba55b34f152d82be16fbf597625bea8eb6 Mon Sep 17 00:00:00 2001 From: Christopher Wellons Date: Sun, 3 May 2020 14:28:21 -0400 Subject: [PATCH] Support binary stdin/stdout on Windows It's now possible to pipe files over standard input and standard output in Windows. --- README.md | 6 ------ src/enchive.c | 8 ++++++++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index dc4bce7..ae78665 100644 --- a/README.md +++ b/README.md @@ -105,11 +105,6 @@ A purposeful design choice is that encrypted/archived files have no distinguishing marks whatsoever (magic numbers, etc.), making them indistinguishable from random data. -No effort is made to set stdin and stdout to binary mode. For Windows -this means passing data through Enchive using stdin/stdout isn't -useful. This is low priority because Microsoft's [UCRT file streams -are broken anyway][pipe] when pipes are involved. - ### Frequently asked questions > This tool will never achieve critical mass, so what's the point? @@ -291,6 +286,5 @@ Maximum passphrase size in bytes, including null terminator. [getrandom]: https://manpages.debian.org/testing/manpages-dev/getrandom.2.en.html [getentropy]: http://man.openbsd.org/OpenBSD-current/man2/getentropy.2 [csp]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa380246(v=vs.85).aspx -[pipe]: https://radiance-online.org/pipermail/radiance-dev/2016-March/001576.html [bw]: https://en.bitcoin.it/wiki/Brainwallet [dw]: http://world.std.com/~reinhold/diceware.html diff --git a/src/enchive.c b/src/enchive.c index 0d2d1cc..c236303 100644 --- a/src/enchive.c +++ b/src/enchive.c @@ -1593,6 +1593,14 @@ main(int argc, char **argv) exit(EXIT_FAILURE); } +#ifdef _WIN32 + { /* Set stdin/stdout to binary mode. */ + int _setmode(int, int); + _setmode(0, 0x8000); + _setmode(1, 0x8000); + } +#endif + switch (parse_command(command)) { case COMMAND_UNKNOWN: case COMMAND_AMBIGUOUS: