Skip to content

Commit

Permalink
Set stdout/stdin to binary mode on Windows
Browse files Browse the repository at this point in the history
Summary:
A file opened in text mode on Windows will have `\n` automatically changed to `13,10` while Darwin and Linux leave it as `10`.

Set the file to binary mode to avoid this automatic conversion so that Darwin, Linux and Windows have equivalent treatment of `\r`.

Reviewers: clayborg, xiaobai

Reviewed By: clayborg

Subscribers: emaste, ki.stfu, mgorny, eraman, JDevlieghere, mgrang

Differential Revision: https://reviews.llvm.org/D52672

llvm-svn: 346174
  • Loading branch information
lanza committed Nov 5, 2018
1 parent 2b80d7f commit c61ee1b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lldb/tools/lldb-vscode/VSCode.cpp
Expand Up @@ -14,6 +14,11 @@
#include "VSCode.h"
#include "LLDBUtils.h"

#if defined(_WIN32)
#include <io.h>
#include <fcntl.h>
#endif

using namespace lldb_vscode;

namespace {
Expand All @@ -39,6 +44,13 @@ VSCode::VSCode()
focus_tid(LLDB_INVALID_THREAD_ID), sent_terminated_event(false),
stop_at_entry(false) {
const char *log_file_path = getenv("LLDBVSCODE_LOG");
#if defined(_WIN32)
// Windows opens stdout and stdin in text mode which converts \n to 13,10
// while the value is just 10 on Darwin/Linux. Setting the file mode to binary
// fixes this.
assert(_setmode(fileno(stdout), _O_BINARY));
assert(_setmode(fileno(stdin), _O_BINARY));
#endif
if (log_file_path)
log.reset(new std::ofstream(log_file_path));
}
Expand Down

0 comments on commit c61ee1b

Please sign in to comment.