diff --git a/client/readline.cc b/client/readline.cc index 6b9e8239984..e4014658c08 100644 --- a/client/readline.cc +++ b/client/readline.cc @@ -64,13 +64,8 @@ char *batch_readline(LINE_BUFFER *line_buff, bool binary_mode) return 0; if (out_length && pos[out_length-1] == '\n') { - /* - On Windows platforms we also need to remove '\r', unconditionally. On - Unix-like platforms we only remove it if we are not on binary mode. - */ - /* Remove '\n' */ - if (--out_length && IF_WIN(1,!binary_mode) && pos[out_length-1] == '\r') + if (--out_length && !binary_mode && pos[out_length-1] == '\r') /* Remove '\r' */ out_length--; } diff --git a/mysql-test/main/mysql_binary_mode.result b/mysql-test/main/mysql_binary_mode.result index cb230037108..59d25199129 100644 --- a/mysql-test/main/mysql_binary_mode.result +++ b/mysql-test/main/mysql_binary_mode.result @@ -29,8 +29,6 @@ RESET MASTER; # It creates the table with a wrong table name and generates an error. # (error output was suppressed to make the test case platform agnostic) -# It is not in binary_mode, so table name '0x410D0A42' can be translated to -# '0x410A42' by mysql depending on the OS - Windows or Unix-like. DROP TABLE `TABLE_NAME_MASKED`; # In binary_mode, table name '0x410D0A42' and string '0x410042' can be @@ -46,5 +44,5 @@ DROP TABLE `A B`; RESET MASTER; include/assert.inc [Table and contents created through mysqltest match 0x610D0A62.] -include/assert.inc [Table and contents created while replaying binary log without --binary-mode set match 0x61(0D)0A62.] +include/assert.inc [Table and contents created while replaying binary log without --binary-mode set match 0x610A62.] include/assert.inc [Table and contents created while replaying binary log with --binary-mode set match 0x610D0A62.] diff --git a/mysql-test/main/mysql_binary_mode.test b/mysql-test/main/mysql_binary_mode.test index d454bfb7624..76af372ac30 100644 --- a/mysql-test/main/mysql_binary_mode.test +++ b/mysql-test/main/mysql_binary_mode.test @@ -48,27 +48,15 @@ RESET MASTER; --echo # It creates the table with a wrong table name and generates an error. --echo # (error output was suppressed to make the test case platform agnostic) -## disabling result log because the error message has the -## table name in the output which is one byte different ('\r') -## on unixes and windows. + --disable_result_log --error 1 --exec $MYSQL test < $MYSQLTEST_VARDIR/tmp/my.sql 2>&1 --enable_result_log --echo ---echo # It is not in binary_mode, so table name '0x410D0A42' can be translated to ---echo # '0x410A42' by mysql depending on the OS - Windows or Unix-like. --replace_result $table_name_wrong TABLE_NAME_MASKED $table_name_right TABLE_NAME_MASKED -if (`SELECT CONVERT(@@VERSION_COMPILE_OS USING latin1) IN ('Win32', 'Win64', 'Windows')`) -{ - eval DROP TABLE `$table_name_right`; -} - -if (`SELECT CONVERT(@@VERSION_COMPILE_OS USING latin1) NOT IN ('Win32', 'Win64', 'Windows')`) -{ - eval DROP TABLE `$table_name_wrong`; -} +eval DROP TABLE `$table_name_wrong`; --echo --echo # In binary_mode, table name '0x410D0A42' and string '0x410042' can be @@ -150,15 +138,9 @@ RESET MASTER; --let $assert_cond= "$tbl0" = "610D0A62" AND "$val0" = "610D0A62" --source include/assert.inc ---let $assert_text= Table and contents created while replaying binary log without --binary-mode set match 0x61(0D)0A62. -if (`SELECT CONVERT(@@VERSION_COMPILE_OS USING latin1) IN ('Win32', 'Win64', 'Windows')`) -{ - --let $assert_cond= "$tbl1" = "610D0A62" AND "$val1" = "610D0A62" -} -if (`SELECT CONVERT(@@VERSION_COMPILE_OS USING latin1) NOT IN ('Win32', 'Win64', 'Windows')`) -{ - --let $assert_cond= "$tbl1" = "610A62" AND "$val1" = "610A62" -} +--let $assert_text= Table and contents created while replaying binary log without --binary-mode set match 0x610A62. +--let $assert_cond= "$tbl1" = "610A62" AND "$val1" = "610A62" + --source include/assert.inc --let $assert_text= Table and contents created while replaying binary log with --binary-mode set match 0x610D0A62. diff --git a/mysys/my_init.c b/mysys/my_init.c index 2f21bcb735f..44488e5848a 100644 --- a/mysys/my_init.c +++ b/mysys/my_init.c @@ -401,16 +401,15 @@ static void my_win_init(void) _tzset(); - /* - We do not want text translation (LF->CRLF) - when stdout is console/terminal, it is buggy - */ - if (fileno(stdout) >= 0 && isatty(fileno(stdout))) - (void)setmode(fileno(stdout), O_BINARY); - - if (fileno(stderr) >= 0 && isatty(fileno(stderr))) - (void) setmode(fileno(stderr), O_BINARY); - + /* Disable automatic LF->CRLF translation. */ + FILE* stdf[]= {stdin, stdout, stderr}; + for (int i= 0; i < array_elements(stdf); i++) + { + int fd= fileno(stdf[i]); + if (fd >= 0) + (void) _setmode(fd, O_BINARY); + } + _set_fmode(O_BINARY); setup_codepages(); DBUG_VOID_RETURN; } diff --git a/sql/log.cc b/sql/log.cc index 619d5ffaccd..f62e41d179b 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -9145,8 +9145,9 @@ void sql_perror(const char *message) */ bool reopen_fstreams(const char *filename, FILE *outstream, FILE *errstream) { - if ((outstream && !my_freopen(filename, "a", outstream)) || - (errstream && !my_freopen(filename, "a", errstream))) + static constexpr const char *mode= "a" IF_WIN("t", ); + if ((outstream && !my_freopen(filename, mode, outstream)) || + (errstream && !my_freopen(filename, mode, errstream))) { my_error(ER_CANT_CREATE_FILE, MYF(0), filename, errno); return TRUE;