[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 8746a1c 3/5: Set msw binary streams in a comp
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 8746a1c 3/5: Set msw binary streams in a compiler-independent way |
Date: |
Thu, 27 Apr 2017 11:54:07 -0400 (EDT) |
branch: master
commit 8746a1c782dde48212306fb836560f70cbab208e
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Set msw binary streams in a compiler-independent way
Added '_' prefix as recommended by ms. Apparently mingw has supported
this for a very long time.
Arguably the return code should be checked. However, if it indicates
failure, then the only reasonable thing to do is to print an error
message on one of the output streams that is being reset; but they
must not be written to before they're reset. Furthermore, cgicc
resets them, redundantly (it would appear), which is perhaps an
error itself. Because this code has worked for decades, a tiny and
conservative change seems wise.
---
cpp_main.cpp | 9 ++++++---
main_common.cpp | 9 ++++++---
2 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/cpp_main.cpp b/cpp_main.cpp
index 385bca1..9b2896c 100644
--- a/cpp_main.cpp
+++ b/cpp_main.cpp
@@ -63,10 +63,13 @@
#include "license.hpp"
#include <cstdlib> // std::free()
+#include <iostream>
+
#if defined LMI_MSW
# include <fcntl.h> // _O_BINARY
+# include <io.h> // _setmode()
+# include <stdio.h> // _fileno()
#endif // defined LMI_MSW
-#include <iostream>
#if defined __MINGW32__
/// Conform to C99 [7.19.6.1/8]:
@@ -148,8 +151,8 @@ 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);
+ _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.
diff --git a/main_common.cpp b/main_common.cpp
index 409dd05..3f8a9d5 100644
--- a/main_common.cpp
+++ b/main_common.cpp
@@ -29,10 +29,13 @@
#include <csignal>
#include <exception> // std::set_terminate()
+#include <stdexcept>
+
#if defined LMI_MSW
# include <fcntl.h> // _O_BINARY
+# include <io.h> // _setmode()
+# include <stdio.h> // _fileno()
#endif // defined LMI_MSW
-#include <stdexcept>
#if defined __MINGW32__
/// Conform to C99 [7.19.6.1/8]:
@@ -67,8 +70,8 @@ void initialize_application()
{
#if defined LMI_MSW
// Force standard output streams to binary mode.
- setmode(fileno(stdout), O_BINARY);
- setmode(fileno(stderr), O_BINARY);
+ _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.