From 8c05cf2e1cb0a90d50c2935d49bd7344acc134f6 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 27 Aug 2018 14:17:50 +1000 Subject: [PATCH] posix/fd: double check the user has specified binary mode --- posix/fd.cpp | 9 ++++++++- posix/fd.hpp | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/posix/fd.cpp b/posix/fd.cpp index 091916f0..64a226b4 100644 --- a/posix/fd.cpp +++ b/posix/fd.cpp @@ -27,7 +27,14 @@ fd::fd (const std::experimental::filesystem::path &path, int flags): //----------------------------------------------------------------------------- fd::fd (const std::experimental::filesystem::path &path, int flags, mode_t mode): m_fd (error::try_value (::open (path.u8string ().c_str (), flags, mode))) -{ ; } +{ + // You always want binary mode. Always. + // + // But we want the user to have considered this platform issue regardless + // so we won't forcibly set the flag, but we will abort the program when + // debugging if they've failed to do so. + CHECK_EQ (flags & O_BINARY, O_BINARY); +} /////////////////////////////////////////////////////////////////////////////// diff --git a/posix/fd.hpp b/posix/fd.hpp index 8e59b0e8..afbfff8b 100644 --- a/posix/fd.hpp +++ b/posix/fd.hpp @@ -23,6 +23,9 @@ namespace cruft::posix { class fd { public: /////////////////////////////////////////////////////////////////////// + // If you are using a system which delineates between binary/text mode + // for descriptors the behaviour is undefined if you don't set the + // necessary flags for binary mode. fd (const std::experimental::filesystem::path &path, int flags); fd (const std::experimental::filesystem::path &path, int flags, mode_t);