[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master b47c9d4: Force standard output streams to bin
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master b47c9d4: Force standard output streams to binary mode |
Date: |
Mon, 22 Aug 2016 21:31:36 +0000 (UTC) |
branch: master
commit b47c9d49177f6a57863184929d63e69fba735bb7
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Force standard output streams to binary mode
See:
http://lists.nongnu.org/archive/html/lmi/2016-08/msg00015.html
---
cpp_main.cpp | 9 +++++++++
main_common.cpp | 9 +++++++++
test_coding_rules.cpp | 24 ------------------------
3 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/cpp_main.cpp b/cpp_main.cpp
index 76f86b3..1e7d547 100644
--- a/cpp_main.cpp
+++ b/cpp_main.cpp
@@ -63,6 +63,9 @@
#include "license.hpp"
#include <cstdlib> // std::free()
+#if defined LMI_MSW
+# include <fcntl.h> // _O_BINARY
+#endif // defined LMI_MSW
#include <iostream>
#if defined __MINGW32__
@@ -143,6 +146,12 @@ namespace lmi_test
int main(int argc, char* argv[])
{
+#if defined LMI_MSW
+ // Force standard output streams to binary mode.
+ setmode(fileno(stdout), O_BINARY);
+ setmode(fileno(stderr), O_BINARY);
+#endif // defined LMI_MSW
+
// This line forces mpatrol to link when it otherwise might not.
// It has no other effect according to C99 7.20.3.2/2, second
// sentence.
diff --git a/main_common.cpp b/main_common.cpp
index f2dc986..38c312a 100644
--- a/main_common.cpp
+++ b/main_common.cpp
@@ -29,6 +29,9 @@
#include <csignal>
#include <exception> // std::set_terminate()
+#if defined LMI_MSW
+# include <fcntl.h> // _O_BINARY
+#endif // defined LMI_MSW
#include <stdexcept>
#if defined __MINGW32__
@@ -62,6 +65,12 @@ void initialize_application()
std::set_terminate(lmi_terminate_handler);
try
{
+#if defined LMI_MSW
+ // Force standard output streams to binary mode.
+ setmode(fileno(stdout), O_BINARY);
+ setmode(fileno(stderr), O_BINARY);
+#endif // defined LMI_MSW
+
// This line forces mpatrol to link when it otherwise might not.
// It has no other effect according to C99 7.20.3.2/2, second
// sentence.
diff --git a/test_coding_rules.cpp b/test_coding_rules.cpp
index f406398..2698edc 100644
--- a/test_coding_rules.cpp
+++ b/test_coding_rules.cpp
@@ -50,30 +50,6 @@ std::string my_taboo_indulgence(); // See
'my_test_coding_rules.cpp'.
std::map<std::string, bool> my_taboos(); // See 'my_test_coding_rules.cpp'.
-// Open predefined standard streams in binary mode.
-//
-// There is no portable way to do this. Of course, it doesn't matter
-// on *nix anyway.
-//
-// SOMEDAY !! Consider moving this to 'main_common.cpp'. The issue is
-// that there are two behaviors:
-// (1) open all files in binary mode
-// (2) open predefined streams in binary mode before main()
-// and we want only (2) and not (1), but MinGW doesn't permit that.
-// For portable correctness, we should take care to open all streams
-// in binary mode; but if we fail to do so, then (1) masks the defect.
-// Yet MinGW offers only
-// (a) '_fmode' --> (1) only
-// (b) '_CRT_fmode' --> both (1) and (2)
-// and not [(2) and not (1)]. It is not sufficient to override
-// '_fmode' on the first line of main() because non-local objects can
-// be constructed before main() is called.
-
-#if defined __MINGW32__
-# include <fcntl.h> // _O_BINARY
- int _CRT_fmode = _O_BINARY;
-#endif // defined __MINGW32__
-
enum enum_phylum
{e_no_phylum = 0
,e_binary = 1 << 0
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [lmi-commits] [lmi] master b47c9d4: Force standard output streams to binary mode,
Greg Chicares <=