diff options
author | 2017-02-09 00:03:00 +0100 | |
---|---|---|
committer | 2017-02-10 21:53:01 +0100 | |
commit | 9a71daa2e000abd0f07f1b43b848124c81958005 (patch) | |
tree | b2be98c1ed3d455b44097bd5f254254cd12bdcf7 /src/lib/netlist/plib/pstream.cpp | |
parent | ab17457707eaab1ec5d3f4719704ccd25a235651 (diff) |
Make windows builds of nltool and nlwav understand unicode.
nltool and nlwav now use wmain, i.e. UNICODE main on windows. (nw)
Diffstat (limited to 'src/lib/netlist/plib/pstream.cpp')
-rw-r--r-- | src/lib/netlist/plib/pstream.cpp | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/src/lib/netlist/plib/pstream.cpp b/src/lib/netlist/plib/pstream.cpp index efbf2aa2374..c43c3b0a174 100644 --- a/src/lib/netlist/plib/pstream.cpp +++ b/src/lib/netlist/plib/pstream.cpp @@ -5,13 +5,20 @@ * */ +#include "pstream.h" +#include "palloc.h" + #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> -#include "pstream.h" -#include "palloc.h" +// VS2015 prefers _dup +#ifdef _WIN32 +#include <io.h> +#else +#include <unistd.h> +#endif namespace plib { @@ -167,7 +174,10 @@ void pofilestream::init() pofilestream::~pofilestream() { if (m_actually_close) + { + fflush(static_cast<FILE *>(m_file)); fclose(static_cast<FILE *>(m_file)); + } } void pofilestream::vwrite(const void *buf, const pos_type n) @@ -175,6 +185,7 @@ void pofilestream::vwrite(const void *buf, const pos_type n) std::size_t r = fwrite(buf, 1, n, static_cast<FILE *>(m_file)); if (r < n) { + //printf("%ld %ld %s\n", r, n, strerror(errno)); if (ferror(static_cast<FILE *>(m_file))) throw file_write_e(m_filename); } @@ -214,7 +225,11 @@ postringstream::~postringstream() // ----------------------------------------------------------------------------- pstderr::pstderr() -: pofilestream(stderr, "<stderr>", false) +#ifdef _WIN32 +: pofilestream(fdopen(_dup(fileno(stderr)), "wb"), "<stderr>", true) +#else +: pofilestream(fdopen(dup(fileno(stderr)), "wb"), "<stderr>", true) +#endif { } @@ -227,7 +242,11 @@ pstderr::~pstderr() // ----------------------------------------------------------------------------- pstdout::pstdout() -: pofilestream(stdout, "<stdout>", false) +#ifdef _WIN32 +: pofilestream(fdopen(_dup(fileno(stdout)), "wb"), "<stdout>", true) +#else +: pofilestream(fdopen(dup(fileno(stdout)), "wb"), "<stdout>", true) +#endif { } |