From d61341c0e3769ec4b9bfb7c2f2b0e98cd3834741 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Mon, 8 Mar 2021 16:36:08 +0100 Subject: [PATCH] io/FileDescriptor: add method SetBinaryMode() --- src/io/FileDescriptor.cxx | 10 +++++++++- src/io/FileDescriptor.hxx | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/io/FileDescriptor.cxx b/src/io/FileDescriptor.cxx index 08b457831..8351446c6 100644 --- a/src/io/FileDescriptor.cxx +++ b/src/io/FileDescriptor.cxx @@ -172,7 +172,15 @@ FileDescriptor::CreatePipe(FileDescriptor &r, FileDescriptor &w) noexcept #endif } -#ifndef _WIN32 +#ifdef _WIN32 + +void +FileDescriptor::SetBinaryMode() noexcept +{ + _setmode(fd, _O_BINARY); +} + +#else // !_WIN32 bool FileDescriptor::CreatePipeNonBlock(FileDescriptor &r, diff --git a/src/io/FileDescriptor.hxx b/src/io/FileDescriptor.hxx index 186c5870c..a036d0d58 100644 --- a/src/io/FileDescriptor.hxx +++ b/src/io/FileDescriptor.hxx @@ -148,10 +148,13 @@ public: #ifdef _WIN32 void EnableCloseOnExec() noexcept {} void DisableCloseOnExec() noexcept {} + void SetBinaryMode() noexcept; #else static bool CreatePipeNonBlock(FileDescriptor &r, FileDescriptor &w) noexcept; + void SetBinaryMode() noexcept {} + /** * Enable non-blocking mode on this file descriptor. */