Commit aec43216 authored by Vladislav Vaintroub's avatar Vladislav Vaintroub

MDEV-9409 Windows - workaround VS2015 CRT bug that makes

mysqldump/mysql_install_db.exe fail

The bug is described in
https://connect.microsoft.com/VisualStudio/Feedback/Details/1902345

When reading from a pipe in text mode, using CRT function such as fread(),
some newlines may be lost. Workaround is to use binary mode on reading side
and if necessary, replace \r\n with \n.
parent 6e257274
......@@ -1705,11 +1705,11 @@ int cat_file(DYNAMIC_STRING* ds, const char* filename)
while((len= my_read(fd, (uchar*)&buff,
sizeof(buff)-1, MYF(0))) > 0)
{
char *p= buff, *start= buff;
while (p < buff+len)
char *p= buff, *start= buff,*end=buff+len;
while (p < end)
{
/* Convert cr/lf to lf */
if (*p == '\r' && *(p+1) && *(p+1)== '\n')
if (*p == '\r' && p+1 < end && *(p+1)== '\n')
{
/* Add fake newline instead of cr and output the line */
*p= '\n';
......@@ -3367,16 +3367,32 @@ void do_exec(struct st_command *command)
ds_result= &ds_sorted;
}
#ifdef _WIN32
/* Workaround for CRT bug, MDEV-9409 */
_setmode(fileno(res_file), O_BINARY);
#endif
while (fgets(buf, sizeof(buf), res_file))
{
int len = (int)strlen(buf);
#ifdef _WIN32
/* Strip '\r' off newlines. */
if (len > 1 && buf[len-2] == '\r' && buf[len-1] == '\n')
{
buf[len-2] = '\n';
buf[len-1] = 0;
len--;
}
#endif
if (disable_result_log)
{
buf[strlen(buf)-1]=0;
if (len)
buf[len-1] = 0;
DBUG_PRINT("exec_result",("%s", buf));
}
else
{
replace_dynstr_append(ds_result, buf);
replace_dynstr_append_mem(ds_result, buf, len);
}
}
error= pclose(res_file);
......@@ -5200,7 +5216,7 @@ typedef struct
static st_error global_error_names[] =
{
{ "<No error>", -1U, "" },
{ "<No error>", ~0U, "" },
#include <mysqld_ername.h>
{ 0, 0, 0 }
};
......
......@@ -4949,6 +4949,12 @@ int mysqld_main(int argc, char **argv)
setbuf(stderr, NULL);
FreeConsole(); // Remove window
}
if (fileno(stdin) >= 0)
{
/* Disable CRLF translation (MDEV-9409). */
_setmode(fileno(stdin), O_BINARY);
}
#endif
/*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment