1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00

Minor windows fixes

This commit is contained in:
Georg Richter
2015-04-07 17:06:35 +02:00
parent ec631f3bd9
commit 8680b5794f
4 changed files with 49 additions and 9 deletions

View File

@@ -264,7 +264,6 @@ inline double ulonglong2double(ulonglong value)
#define statistic_increment(V,L) thread_safe_increment((V),(L))
#define strcasecmp(A,B) _stricmp((A),(B))
#define close(A) _close((A))
#define fdopen(A,B) _fdopen((A),(B))
#define sopen(A,B,C,D) _sopen((A),(B),(C),(D))

View File

@@ -1,3 +1,20 @@
/* Copyright (C) 2015 MariaDB Corporation AB
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
MA 02111-1307, USA */
#ifndef _ma_io_h_
#define _ma_io_h_

View File

@@ -43,27 +43,31 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql)
#ifdef _WIN32
if (mysql && mysql->charset)
CodePage= madb_get_windows_cp(mysql->charset);
CodePage= madb_get_windows_cp(mysql->charset->csname);
#endif
if (CodePage == -1)
{
if (!(fp= fopen(location, mode)))
{
#ifdef WIN32
#ifdef _WIN32
my_errno= GetLastError();
#else
my_errno= errno;
#endif
return NULL;
}
#ifdef WIN32
}
#ifdef _WIN32
/* See CONC-44: we need to support non ascii filenames too, so we convert
current character set to wchar_t and try to open the file via _wsopen */
else
{
wchar_t *filename= NULL;
wchar_t *w_filename= NULL;
wchar_t *w_mode= NULL;
int len;
DWORD Length;
len= MultiByteToWideChar(CodePage, 0, location, (int)strlen(location), NULL, 0)M;
len= MultiByteToWideChar(CodePage, 0, location, (int)strlen(location), NULL, 0);
if (!len)
return NULL;
if (!(w_filename= (wchar_t *)my_malloc((len + 1) * sizeof(wchar_t), MYF(MY_ZEROFILL))))
@@ -71,6 +75,7 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql)
my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
return NULL;
}
Length= len;
len= MultiByteToWideChar(CodePage, 0, location, (int)strlen(location), w_filename, (int)Length);
if (!len)
{
@@ -78,10 +83,28 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql)
my_free(w_filename);
return NULL;
}
fp= _wfopen(w_filename, mode);
len= strlen(mode);
if (!(w_mode= (wchar_t *)my_malloc((len + 1) * sizeof(wchar_t), MYF(MY_ZEROFILL))))
{
my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0);
my_free(w_filename);
return NULL;
}
Length= len;
len= MultiByteToWideChar(CodePage, 0, mode, (int)strlen(mode), w_mode, (int)Length);
if (!len)
{
/* todo: error handling */
my_free(w_filename);
my_free(w_mode);
return NULL;
}
fp= _wfopen(w_filename, w_mode);
my_errno= GetLastError();
my_free(w_filename);
my_free(w_mode);
}
#endif
if (fp)
{

View File

@@ -856,7 +856,8 @@ static int test_ldi_path(MYSQL *mysql)
"FIELDS TERMINATED BY '.' LINES TERMINATED BY '\r\n'");
#endif
FAIL_IF(rc== 0, "Error expected");
FAIL_IF(mysql_errno(mysql) != 2, "Error code 2 expected");
diag("Error: %d", mysql_errno(mysql));
FAIL_IF(mysql_errno(mysql) == 0, "Error expected");
rc= mysql_query(mysql, "DROP TABLE t1");
check_mysql_rc(rc, mysql);