Skip to content

Commit

Permalink
On Win32 put the console into binary mode to correctly handle '\r\n' …
Browse files Browse the repository at this point in the history
…output.

By default, Win32 writes ^M^J for '\n'. Explicitly writing '\r\n' doubles the ^M.
  • Loading branch information
tplunket committed May 26, 2016
1 parent 8d278f7 commit 6ee784f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
#include "search.h"
#include "util.h"

#ifdef _WIN32
static int old_mode = _O_TEXT;
void restore_stdout() {
fflush(stdout);
_setmode(fileno(stdout), _O_TEXT);
}
#endif

typedef struct {
pthread_t thread;
int id;
Expand Down Expand Up @@ -47,7 +55,13 @@ int main(int argc, char **argv) {
work_queue_tail = NULL;
memset(&stats, 0, sizeof(stats));
root_ignores = init_ignore(NULL, "", 0);

#ifdef _WIN32
old_mode = _setmode(fileno(stdout), _O_BINARY);
atexit(restore_stdout);
#endif
out_fd = stdout;

#ifdef USE_PCRE_JIT
int has_jit = 0;
pcre_config(PCRE_CONFIG_JIT, &has_jit);
Expand Down

0 comments on commit 6ee784f

Please sign in to comment.