From 336590052d93979eb90412cc4cabb2f5f6fd1b74 Mon Sep 17 00:00:00 2001 From: Hadis Kakanejadi Fard Date: Tue, 24 Jan 2017 17:18:20 -0800 Subject: [PATCH] merged core_stream --- source/shared/core_stream.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/source/shared/core_stream.cpp b/source/shared/core_stream.cpp index 08b01d05..788c00ae 100644 --- a/source/shared/core_stream.cpp +++ b/source/shared/core_stream.cpp @@ -18,7 +18,6 @@ //--------------------------------------------------------------------------------------------------------------------------------- #include "core_sqlsrv.h" -#include namespace { @@ -80,6 +79,7 @@ size_t sqlsrv_stream_read( php_stream* stream, _Out_writes_bytes_(count) char* b // use a temporary buffer to retrieve from SQLGetData since we need to translate it to UTF-8 from UTF-16 temp_buf = static_cast( sqlsrv_malloc( PHP_STREAM_BUFFER_SIZE )); + memset(temp_buf, 0, PHP_STREAM_BUFFER_SIZE); get_data_buffer = temp_buf; break; } @@ -147,23 +147,29 @@ size_t sqlsrv_stream_read( php_stream* stream, _Out_writes_bytes_(count) char* b // flags set to 0 by default, which means that any invalid characters are dropped rather than causing // an error. This happens only on XP. - DWORD flags = 0; // convert to UTF-8 +#ifndef __linux__ + DWORD flags = 0; + if (g_osversion.dwMajorVersion >= SQLSRV_OS_VISTA_OR_LATER) { // Vista (and later) will detect invalid UTF-16 characters and raise an error. flags = WC_ERR_INVALID_CHARS; } - +#endif if ( count > INT_MAX || (read >> 1) > INT_MAX ) { LOG(SEV_ERROR, "UTF-16 (wide character) string mapping: buffer length exceeded."); throw core::CoreException(); } +#ifdef __linux__ + int enc_len = SystemLocale::FromUtf16( ss->encoding, reinterpret_cast( temp_buf.get() ), + static_cast(read >> 1), buf, static_cast(count), NULL, NULL ); +#else int enc_len = WideCharToMultiByte( ss->encoding, flags, reinterpret_cast( temp_buf.get() ), static_cast(read >> 1), buf, static_cast(count), NULL, NULL ); - +#endif if( enc_len == 0 ) { stream->eof = 1;