merged core_stream

This commit is contained in:
Hadis Kakanejadi Fard 2017-01-24 17:18:20 -08:00
parent 3afe7fe883
commit 336590052d

View file

@ -18,7 +18,6 @@
//---------------------------------------------------------------------------------------------------------------------------------
#include "core_sqlsrv.h"
#include <windows.h>
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<char*>( 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<LPCWSTR>( temp_buf.get() ),
static_cast<int>(read >> 1), buf, static_cast<int>(count), NULL, NULL );
#else
int enc_len = WideCharToMultiByte( ss->encoding, flags, reinterpret_cast<LPCWSTR>( temp_buf.get() ),
static_cast<int>(read >> 1), buf, static_cast<int>(count), NULL, NULL );
#endif
if( enc_len == 0 ) {
stream->eof = 1;