diff options
-rw-r--r-- | sal/osl/w32/conditn.cxx | 10 | ||||
-rw-r--r-- | sal/osl/w32/dllentry.cxx | 12 | ||||
-rw-r--r-- | sal/osl/w32/file_dirvol.cxx | 4 | ||||
-rw-r--r-- | sal/osl/w32/file_url.cxx | 8 | ||||
-rw-r--r-- | sal/osl/w32/module.cxx | 47 | ||||
-rw-r--r-- | sal/osl/w32/nlsupport.cxx | 2 | ||||
-rw-r--r-- | sal/osl/w32/pipe.cxx | 6 | ||||
-rw-r--r-- | sal/osl/w32/process.cxx | 18 | ||||
-rw-r--r-- | sal/osl/w32/procimpl.cxx | 4 | ||||
-rw-r--r-- | sal/osl/w32/profile.cxx | 119 | ||||
-rw-r--r-- | sal/osl/w32/socket.cxx | 5 | ||||
-rw-r--r-- | sal/osl/w32/tempfile.cxx | 8 | ||||
-rw-r--r-- | sal/qa/osl/security/osl_Security.cxx | 54 | ||||
-rw-r--r-- | sal/rtl/alloc_cache.cxx | 2 |
14 files changed, 183 insertions, 116 deletions
diff --git a/sal/osl/w32/conditn.cxx b/sal/osl/w32/conditn.cxx index 9807eaa95863..6bc6d9d3ed3a 100644 --- a/sal/osl/w32/conditn.cxx +++ b/sal/osl/w32/conditn.cxx @@ -32,10 +32,10 @@ oslCondition SAL_CALL osl_createCondition(void) { oslCondition Condition; - Condition= reinterpret_cast<oslCondition>(CreateEvent(nullptr, /* no security */ - true, /* manual reset */ - false, /* initial state not signaled */ - nullptr)); /* automatic name */ + Condition= reinterpret_cast<oslCondition>(CreateEventW(nullptr, /* no security */ + true, /* manual reset */ + false, /* initial state not signaled */ + nullptr)); /* automatic name */ return Condition; @@ -88,7 +88,7 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, /* We Must not dispatch the message. PM_NOREMOVE leaves the message queue untouched but dispatches SendMessage calls automatically */ - PeekMessage( &msg, nullptr, 0, 0, PM_NOREMOVE ); + PeekMessageW( &msg, nullptr, 0, 0, PM_NOREMOVE ); } break; diff --git a/sal/osl/w32/dllentry.cxx b/sal/osl/w32/dllentry.cxx index bc575ac5b7d8..52159853eb3e 100644 --- a/sal/osl/w32/dllentry.cxx +++ b/sal/osl/w32/dllentry.cxx @@ -66,8 +66,8 @@ static BOOL WINAPI RawDllMain( HINSTANCE, DWORD fdwReason, LPVOID ) { #ifdef _DEBUG WCHAR buf[64]; - DWORD const res = GetEnvironmentVariableW(L"SAL_NO_ASSERT_DIALOGS", buf, sizeof(buf)); - if (res && res < sizeof(buf)) + DWORD const res = GetEnvironmentVariableW(L"SAL_NO_ASSERT_DIALOGS", buf, SAL_N_ELEMENTS(buf)); + if (res && res < SAL_N_ELEMENTS(buf)) { // disable the dialog on abort() _CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR); @@ -203,20 +203,20 @@ BOOL WINAPI DllMain( HINSTANCE, DWORD fdwReason, LPVOID ) { case DLL_PROCESS_ATTACH: { - TCHAR szBuffer[64]; + WCHAR szBuffer[64]; // This code will attach the process to its parent process // if the parent process had set the environment variable. // The corresponding code (setting the environment variable) // is desktop/win32/source/officeloader.cxx - DWORD dwResult = GetEnvironmentVariable( "ATTACHED_PARENT_PROCESSID", szBuffer, sizeof(szBuffer) ); + DWORD dwResult = GetEnvironmentVariableW( L"ATTACHED_PARENT_PROCESSID", szBuffer, SAL_N_ELEMENTS(szBuffer) ); - if ( dwResult && dwResult < sizeof(szBuffer) ) + if ( dwResult && dwResult < SAL_N_ELEMENTS(szBuffer) ) { DWORD dwThreadId = 0; - DWORD_PTR dwParentProcessId = (DWORD_PTR)atol( szBuffer ); + DWORD_PTR dwParentProcessId = (DWORD_PTR)_wtol( szBuffer ); if ( dwParentProcessId && GetParentProcessId() == dwParentProcessId ) { diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx index 46f185d0554e..446654f98759 100644 --- a/sal/osl/w32/file_dirvol.cxx +++ b/sal/osl/w32/file_dirvol.cxx @@ -257,9 +257,9 @@ static HANDLE WINAPI OpenLogicalDrivesEnum() LPDRIVEENUM pEnum = static_cast<LPDRIVEENUM>(HeapAlloc( GetProcessHeap(), 0, sizeof(DRIVEENUM) )); if ( pEnum ) { - DWORD dwNumCopied = GetLogicalDriveStringsW( (sizeof(pEnum->cBuffer) - 1) / sizeof(WCHAR), pEnum->cBuffer ); + DWORD dwNumCopied = GetLogicalDriveStringsW( SAL_N_ELEMENTS(pEnum->cBuffer) - 1, pEnum->cBuffer ); - if ( dwNumCopied && dwNumCopied < sizeof(pEnum->cBuffer) / sizeof(WCHAR) ) + if ( dwNumCopied && dwNumCopied < SAL_N_ELEMENTS(pEnum->cBuffer) ) { pEnum->lpCurrent = pEnum->cBuffer; pEnum->lpIdent = L"tagDRIVEENUM"; diff --git a/sal/osl/w32/file_url.cxx b/sal/osl/w32/file_url.cxx index 1a62385bd7e9..88bd38bcac86 100644 --- a/sal/osl/w32/file_url.cxx +++ b/sal/osl/w32/file_url.cxx @@ -675,7 +675,7 @@ oslFileError osl_getSystemPathFromFileURL_( rtl_uString *strURL, rtl_uString **p { ::osl::LongPathBuffer< sal_Unicode > aBuf( MAX_LONG_PATH ); sal_uInt32 nNewLen = GetCaseCorrectPathName( SAL_W(pDecodedURL) + nSkip, - ::osl::mingw_reinterpret_cast<LPWSTR>(aBuf), + SAL_W(aBuf), aBuf.getBufSizeInSymbols(), false ); @@ -975,15 +975,15 @@ oslFileError SAL_CALL osl_getAbsoluteFileURL( rtl_uString* ustrBaseURL, rtl_uStr { osl_acquireMutex( g_CurrentDirectoryMutex ); - GetCurrentDirectoryW( aCurrentDir.getBufSizeInSymbols(), ::osl::mingw_reinterpret_cast<LPWSTR>(aCurrentDir) ); + GetCurrentDirectoryW( aCurrentDir.getBufSizeInSymbols(), SAL_W(aCurrentDir) ); SetCurrentDirectoryW( SAL_W(ustrBaseSysPath->buffer) ); } - dwResult = GetFullPathNameW( SAL_W(ustrRelSysPath->buffer), aBuffer.getBufSizeInSymbols(), ::osl::mingw_reinterpret_cast<LPWSTR>(aBuffer), &lpFilePart ); + dwResult = GetFullPathNameW( SAL_W(ustrRelSysPath->buffer), aBuffer.getBufSizeInSymbols(), SAL_W(aBuffer), &lpFilePart ); if ( ustrBaseSysPath ) { - SetCurrentDirectoryW( ::osl::mingw_reinterpret_cast<LPCWSTR>(aCurrentDir) ); + SetCurrentDirectoryW( SAL_W(aCurrentDir) ); osl_releaseMutex( g_CurrentDirectoryMutex ); } diff --git a/sal/osl/w32/module.cxx b/sal/osl/w32/module.cxx index cdf1665509de..6ba859263ac1 100644 --- a/sal/osl/w32/module.cxx +++ b/sal/osl/w32/module.cxx @@ -52,11 +52,10 @@ oslModule SAL_CALL osl_loadModule(rtl_uString *strModuleName, sal_Int32 /*nRtldM if ( osl_File_E_None != nError ) rtl_uString_assign(&Module, strModuleName); - h = LoadLibraryW(reinterpret_cast<LPCWSTR>(Module->buffer)); + h = LoadLibraryW(SAL_W(Module->buffer)); if (h == nullptr) - h = LoadLibraryExW(reinterpret_cast<LPCWSTR>(Module->buffer), nullptr, - LOAD_WITH_ALTERED_SEARCH_PATH); + h = LoadLibraryExW(SAL_W(Module->buffer), nullptr, LOAD_WITH_ALTERED_SEARCH_PATH); // In case of long path names (\\?\c:\...) try to shorten the filename. // LoadLibrary cannot handle file names which exceed 260 letters. @@ -66,15 +65,13 @@ oslModule SAL_CALL osl_loadModule(rtl_uString *strModuleName, sal_Int32 /*nRtldM if (h == nullptr && Module->length > 260) { std::vector<WCHAR> vec(Module->length + 1); - DWORD len = GetShortPathNameW(reinterpret_cast<LPCWSTR>(Module->buffer), - reinterpret_cast<LPWSTR>(&vec[0]), Module->length + 1); + DWORD len = GetShortPathNameW(SAL_W(Module->buffer), &vec[0], Module->length + 1); if (len ) { - h = LoadLibraryW(reinterpret_cast<LPWSTR>(&vec[0])); + h = LoadLibraryW(&vec[0]); if (h == nullptr) - h = LoadLibraryExW(reinterpret_cast<LPWSTR>(&vec[0]), nullptr, - LOAD_WITH_ALTERED_SEARCH_PATH); + h = LoadLibraryExW(&vec[0], nullptr, LOAD_WITH_ALTERED_SEARCH_PATH); } } @@ -116,7 +113,7 @@ oslModule osl_loadModuleRelativeAscii( sal_Bool SAL_CALL osl_getModuleHandle(rtl_uString *pModuleName, oslModule *pResult) { - LPCWSTR pName = pModuleName ? reinterpret_cast<LPCWSTR>(pModuleName->buffer) : nullptr; + LPCWSTR pName = pModuleName ? SAL_W(pModuleName->buffer) : nullptr; HMODULE h = GetModuleHandleW(pName); if( h ) { @@ -209,7 +206,7 @@ osl_getAsciiFunctionSymbol( oslModule Module, const sal_Char *pSymbol ) typedef BOOL (WINAPI *SymInitialize_PROC)( HANDLE hProcess, - LPSTR UserSearchPath, + LPWSTR UserSearchPath, BOOL fInvadeProcess ); @@ -220,7 +217,7 @@ typedef BOOL (WINAPI *SymCleanup_PROC)( typedef BOOL (WINAPI *SymGetModuleInfo_PROC)( HANDLE hProcess, DWORD dwAddr, - PIMAGEHLP_MODULE ModuleInfo + PIMAGEHLP_MODULEW ModuleInfo ); /* Seems that IMAGEHLP.DLL is always available on NT 4. But MSDN from Platform SDK says Win 2K is required. MSDN from VS 6.0a says @@ -247,29 +244,29 @@ static bool SAL_CALL osl_addressGetModuleURL_NT4_( void *pv, rtl_uString **pustr SymInitialize_PROC lpfnSymInitialize; SymCleanup_PROC lpfnSymCleanup; - lpfnSymInitialize = reinterpret_cast<SymInitialize_PROC>(GetProcAddress( hModImageHelp, "SymInitialize" )); + lpfnSymInitialize = reinterpret_cast<SymInitialize_PROC>(GetProcAddress( hModImageHelp, "SymInitializeW" )); lpfnSymCleanup = reinterpret_cast<SymCleanup_PROC>(GetProcAddress( hModImageHelp, "SymCleanup" )); - lpfnSymGetModuleInfo = reinterpret_cast<SymGetModuleInfo_PROC>(GetProcAddress( hModImageHelp, "SymGetModuleInfo" )); + lpfnSymGetModuleInfo = reinterpret_cast<SymGetModuleInfo_PROC>(GetProcAddress( hModImageHelp, "SymGetModuleInfoW" )); if ( lpfnSymInitialize && lpfnSymCleanup && lpfnSymGetModuleInfo ) { - IMAGEHLP_MODULE ModuleInfo; - ::osl::LongPathBuffer< sal_Char > aModuleFileName( MAX_LONG_PATH ); - LPSTR lpSearchPath = nullptr; + IMAGEHLP_MODULEW ModuleInfo; + ::osl::LongPathBuffer< sal_Unicode > aModuleFileName( MAX_LONG_PATH ); + LPWSTR lpSearchPath = nullptr; - if ( GetModuleFileNameA( nullptr, aModuleFileName, aModuleFileName.getBufSizeInSymbols() ) ) + if ( GetModuleFileNameW( nullptr, SAL_W(aModuleFileName), aModuleFileName.getBufSizeInSymbols() ) ) { - char *pLastBkSlash = strrchr( aModuleFileName, '\\' ); + wchar_t *pLastBkSlash = wcsrchr( SAL_W(aModuleFileName), L'\\' ); if ( pLastBkSlash && - pLastBkSlash > static_cast<sal_Char*>(aModuleFileName) - && *(pLastBkSlash - 1) != ':' - && *(pLastBkSlash - 1) != '\\' + pLastBkSlash > SAL_W(aModuleFileName) + && *(pLastBkSlash - 1) != L':' + && *(pLastBkSlash - 1) != L'\\' ) { *pLastBkSlash = 0; - lpSearchPath = aModuleFileName; + lpSearchPath = SAL_W(aModuleFileName); } } @@ -287,11 +284,11 @@ static bool SAL_CALL osl_addressGetModuleURL_NT4_( void *pv, rtl_uString **pustr BaseOfImage to a HMODULE (on NT it's the same) and use GetModuleFileName to retrieve the full path of the loaded image */ - if ( ModuleInfo.LoadedImageName[0] || GetModuleFileNameA( reinterpret_cast<HMODULE>(ModuleInfo.BaseOfImage), ModuleInfo.LoadedImageName, sizeof(ModuleInfo.LoadedImageName) ) ) + if ( ModuleInfo.LoadedImageName[0] || GetModuleFileNameW( reinterpret_cast<HMODULE>(ModuleInfo.BaseOfImage), ModuleInfo.LoadedImageName, SAL_N_ELEMENTS(ModuleInfo.LoadedImageName) ) ) { rtl_uString *ustrSysPath = nullptr; - rtl_string2UString( &ustrSysPath, ModuleInfo.LoadedImageName, strlen(ModuleInfo.LoadedImageName), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS ); + rtl_uString_newFromStr( &ustrSysPath, SAL_U(ModuleInfo.LoadedImageName) ); OSL_ASSERT(ustrSysPath != nullptr); osl_getFileURLFromSystemPath( ustrSysPath, pustrURL ); rtl_uString_release( ustrSysPath ); @@ -368,7 +365,7 @@ static bool SAL_CALL osl_addressGetModuleURL_NT_( void *pv, rtl_uString **pustrU ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); rtl_uString *ustrSysPath = nullptr; - GetModuleFileNameW( lpModules[iModule], ::osl::mingw_reinterpret_cast<LPWSTR>(aBuffer), aBuffer.getBufSizeInSymbols() ); + GetModuleFileNameW( lpModules[iModule], SAL_W(aBuffer), aBuffer.getBufSizeInSymbols() ); rtl_uString_newFromStr( &ustrSysPath, aBuffer ); osl_getFileURLFromSystemPath( ustrSysPath, pustrURL ); diff --git a/sal/osl/w32/nlsupport.cxx b/sal/osl/w32/nlsupport.cxx index c3136ae65aa5..8721804fd0b2 100644 --- a/sal/osl/w32/nlsupport.cxx +++ b/sal/osl/w32/nlsupport.cxx @@ -45,7 +45,7 @@ #define ELP_LANGUAGE_FIELD_LENGTH 4 #define ELP_COUNTRY_FIELD_LENGTH 3 -/** Struct used in EnumLocalesProcA() called via EnumSystemLocalesA() to obtain +/** Struct used in EnumLocalesProcW() called via EnumSystemLocalesW() to obtain available locales. */ struct EnumLocalesParams diff --git a/sal/osl/w32/pipe.cxx b/sal/osl/w32/pipe.cxx index 0bb884785a00..2240ade36b6f 100644 --- a/sal/osl/w32/pipe.cxx +++ b/sal/osl/w32/pipe.cxx @@ -70,9 +70,9 @@ oslPipe osl_createPipeImpl(void) pPipe->m_File = INVALID_HANDLE_VALUE; pPipe->m_NamedObject = nullptr; - pPipe->m_ReadEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); - pPipe->m_WriteEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); - pPipe->m_AcceptEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); + pPipe->m_ReadEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr); + pPipe->m_WriteEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr); + pPipe->m_AcceptEvent = CreateEventW(nullptr, TRUE, FALSE, nullptr); return pPipe; } diff --git a/sal/osl/w32/process.cxx b/sal/osl/w32/process.cxx index 07d2c722a762..7d989d548477 100644 --- a/sal/osl/w32/process.cxx +++ b/sal/osl/w32/process.cxx @@ -286,7 +286,7 @@ oslProcessError bootstrap_getExecutableFile(rtl_uString ** ppFileURL) ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); DWORD buflen = 0; - if ((buflen = GetModuleFileNameW (nullptr, ::osl::mingw_reinterpret_cast<LPWSTR>(aBuffer), aBuffer.getBufSizeInSymbols())) > 0) + if ((buflen = GetModuleFileNameW (nullptr, SAL_W(aBuffer), aBuffer.getBufSizeInSymbols())) > 0) { rtl_uString * pAbsPath = nullptr; rtl_uString_newFromStr_WithLength (&pAbsPath, aBuffer, buflen); @@ -336,7 +336,7 @@ static rtl_uString ** osl_createCommandArgs_Impl (int argc, char **) for (i = 0; i < nArgs; i++) { /* Convert to unicode */ - rtl_uString_newFromStr( &(ppArgs[i]), reinterpret_cast<const sal_Unicode*>(wargv[i]) ); + rtl_uString_newFromStr( &(ppArgs[i]), SAL_U(wargv[i]) ); } if (ppArgs[0] != nullptr) { @@ -345,7 +345,7 @@ static rtl_uString ** osl_createCommandArgs_Impl (int argc, char **) DWORD dwResult = 0; dwResult = SearchPathW ( - nullptr, reinterpret_cast<LPCWSTR>(ppArgs[0]->buffer), L".exe", aBuffer.getBufSizeInSymbols(), ::osl::mingw_reinterpret_cast<LPWSTR>(aBuffer), nullptr); + nullptr, SAL_W(ppArgs[0]->buffer), L".exe", aBuffer.getBufSizeInSymbols(), SAL_W(aBuffer), nullptr); if ((0 < dwResult) && (dwResult < aBuffer.getBufSizeInSymbols())) { /* Replace argv[0] with its absolute path */ @@ -445,9 +445,9 @@ oslProcessError SAL_CALL osl_getEnvironment(rtl_uString *ustrVar, rtl_uString ** { WCHAR buff[ENV_BUFFER_SIZE]; - if (GetEnvironmentVariableW(reinterpret_cast<LPCWSTR>(ustrVar->buffer), buff, ENV_BUFFER_SIZE) > 0) + if (GetEnvironmentVariableW(SAL_W(ustrVar->buffer), buff, ENV_BUFFER_SIZE) > 0) { - rtl_uString_newFromStr(ustrValue, reinterpret_cast<const sal_Unicode*>(buff)); + rtl_uString_newFromStr(ustrValue, SAL_U(buff)); return osl_Process_E_None; } return osl_Process_E_Unknown; @@ -456,8 +456,8 @@ oslProcessError SAL_CALL osl_getEnvironment(rtl_uString *ustrVar, rtl_uString ** oslProcessError SAL_CALL osl_setEnvironment(rtl_uString *ustrVar, rtl_uString *ustrValue) { // set Windows environment variable - LPCWSTR lpName = reinterpret_cast<LPCWSTR>(ustrVar->buffer); - LPCWSTR lpValue = reinterpret_cast<LPCWSTR>(ustrValue->buffer); + LPCWSTR lpName = SAL_W(ustrVar->buffer); + LPCWSTR lpValue = SAL_W(ustrValue->buffer); if (SetEnvironmentVariableW(lpName, lpValue)) { auto buffer = std::unique_ptr<wchar_t[]>( @@ -475,7 +475,7 @@ oslProcessError SAL_CALL osl_clearEnvironment(rtl_uString *ustrVar) { // delete the variable from the current process environment // by setting SetEnvironmentVariable's second parameter to NULL - LPCWSTR lpName = reinterpret_cast<LPCWSTR>(ustrVar->buffer); + LPCWSTR lpName = SAL_W(ustrVar->buffer); if (SetEnvironmentVariableW(lpName, nullptr)) { auto buffer = std::unique_ptr<wchar_t[]>( @@ -494,7 +494,7 @@ oslProcessError SAL_CALL osl_getProcessWorkingDir( rtl_uString **pustrWorkingDir DWORD dwLen = 0; osl_acquireMutex( g_CurrentDirectoryMutex ); - dwLen = GetCurrentDirectoryW( aBuffer.getBufSizeInSymbols(), ::osl::mingw_reinterpret_cast<LPWSTR>(aBuffer) ); + dwLen = GetCurrentDirectoryW( aBuffer.getBufSizeInSymbols(), SAL_W(aBuffer) ); osl_releaseMutex( g_CurrentDirectoryMutex ); if ( dwLen && dwLen < aBuffer.getBufSizeInSymbols() ) diff --git a/sal/osl/w32/procimpl.cxx b/sal/osl/w32/procimpl.cxx index bc7617f3a834..0cdc6a2eefbc 100644 --- a/sal/osl/w32/procimpl.cxx +++ b/sal/osl/w32/procimpl.cxx @@ -474,9 +474,9 @@ oslProcessError SAL_CALL osl_executeProcess_WithRedirectedIO( flags |= DETACHED_PROCESS; STARTUPINFOW startup_info; - memset(&startup_info, 0, sizeof(STARTUPINFO)); + memset(&startup_info, 0, sizeof(startup_info)); - startup_info.cb = sizeof(STARTUPINFO); + startup_info.cb = sizeof(startup_info); startup_info.dwFlags = STARTF_USESHOWWINDOW; startup_info.lpDesktop = const_cast<LPWSTR>(L""); diff --git a/sal/osl/w32/profile.cxx b/sal/osl/w32/profile.cxx index 36d28c2c58ed..1e586190b7e7 100644 --- a/sal/osl/w32/profile.cxx +++ b/sal/osl/w32/profile.cxx @@ -30,6 +30,7 @@ #include <rtl/alloc.h> #include <sal/macros.h> #include <algorithm> +#include <vector> using std::min; static inline void copy_ustr_n( void *dest, const void *source, size_t length ) { memcpy(dest, source, length*sizeof(sal_Unicode)); } @@ -355,6 +356,85 @@ static bool writeProfileImpl(osl_TFile* pFile) return true; } +namespace { +// Use Unicode version of GetPrivateProfileString, to work with Multi-language paths +DWORD GetPrivateProfileStringWrapper(const osl_TProfileImpl* pProfile, + const sal_Char* pszSection, const sal_Char* pszEntry, + sal_Char* pszString, sal_uInt32 MaxLen, + const sal_Char* pszDefault) +{ + OSL_ASSERT(pProfile && (!MaxLen || pszString)); + + rtl_uString *pSection = nullptr, *pEntry = nullptr, *pDefault = nullptr; + if (pszSection) + { + rtl_string2UString(&pSection, pszSection, strlen(pszSection), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS); + OSL_ASSERT(pSection); + } + if (pszEntry) + { + rtl_string2UString(&pEntry, pszEntry, strlen(pszEntry), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS); + OSL_ASSERT(pEntry); + } + if (pszDefault) + { + rtl_string2UString(&pDefault, pszDefault, strlen(pszDefault), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS); + OSL_ASSERT(pDefault); + } + + LPCWSTR pWSection = (pSection ? SAL_W(rtl_uString_getStr(pSection)) : nullptr), + pWEntry = (pEntry ? SAL_W(rtl_uString_getStr(pEntry)) : nullptr), + pWDefault = (pDefault ? SAL_W(rtl_uString_getStr(pDefault)) : nullptr); + + std::vector<wchar_t> aBuf(MaxLen + 1); + GetPrivateProfileStringW(pWSection, pWEntry, pWDefault, &aBuf[0], MaxLen, SAL_W(rtl_uString_getStr(pProfile->m_strFileName))); + + if (pDefault) + rtl_uString_release(pDefault); + if (pEntry) + rtl_uString_release(pEntry); + if (pSection) + rtl_uString_release(pSection); + + return WideCharToMultiByte(CP_ACP, 0, &aBuf[0], -1, pszString, MaxLen, nullptr, nullptr); +} + +// Use Unicode version of WritePrivateProfileString, to work with Multi-language paths +BOOL WritePrivateProfileStringWrapper(const osl_TProfileImpl* pProfile, + const sal_Char* pszSection, const sal_Char* pszEntry, + const sal_Char* pszString) +{ + OSL_ASSERT(pProfile && pszSection); + rtl_uString *pSection, *pEntry = nullptr, *pString = nullptr; + rtl_string2UString(&pSection, pszSection, strlen(pszSection), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS); + OSL_ASSERT(pSection); + if (pszEntry) + { + rtl_string2UString(&pEntry, pszEntry, strlen(pszEntry), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS); + OSL_ASSERT(pEntry); + } + if (pszString) + { + rtl_string2UString(&pString, pszString, strlen(pszString), osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS); + OSL_ASSERT(pString); + } + + LPCWSTR pWSection = SAL_W(pSection->buffer), + pWEntry = (pEntry ? SAL_W(rtl_uString_getStr(pEntry)) : nullptr), + pWString = (pString ? SAL_W(rtl_uString_getStr(pString)) : nullptr); + + BOOL bResult = WritePrivateProfileStringW(pWSection, pWEntry, pWString, SAL_W(rtl_uString_getStr(pProfile->m_strFileName))); + + if (pString) + rtl_uString_release(pString); + if (pEntry) + rtl_uString_release(pEntry); + rtl_uString_release(pSection); + + return bResult; +} +} + sal_Bool SAL_CALL osl_readProfileString(oslProfile Profile, const sal_Char* pszSection, const sal_Char* pszEntry, sal_Char* pszString, sal_uInt32 MaxLen, @@ -393,10 +473,8 @@ sal_Bool SAL_CALL osl_readProfileString(oslProfile Profile, } else { - ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - - WideCharToMultiByte(CP_ACP,0, reinterpret_cast<LPCWSTR>(pProfile->m_strFileName->buffer), -1, aFileName, aFileName.getBufSizeInSymbols(), nullptr, nullptr); - GetPrivateProfileString(pszSection, pszEntry, pszDefault, pszString, MaxLen, aFileName); + if (GetPrivateProfileStringWrapper(pProfile, pszSection, pszEntry, pszString, MaxLen, pszDefault) > 0) + pStr = pszString; // required to return true below } releaseProfile(pProfile); @@ -531,10 +609,7 @@ sal_Bool SAL_CALL osl_writeProfileString(oslProfile Profile, } else { - ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - - WideCharToMultiByte(CP_ACP,0, reinterpret_cast<LPCWSTR>(pProfile->m_strFileName->buffer), -1, aFileName, aFileName.getBufSizeInSymbols(), nullptr, nullptr); - WritePrivateProfileString(pszSection, pszEntry, pszString, aFileName); + WritePrivateProfileStringWrapper(pProfile, pszSection, pszEntry, pszString); } bRet = releaseProfile(pProfile); @@ -609,10 +684,7 @@ sal_Bool SAL_CALL osl_removeProfileEntry(oslProfile Profile, } else { - ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - - WideCharToMultiByte(CP_ACP,0, reinterpret_cast<LPCWSTR>(pProfile->m_strFileName->buffer), -1, aFileName, aFileName.getBufSizeInSymbols(), nullptr, nullptr); - WritePrivateProfileString(pszSection, pszEntry, nullptr, aFileName); + WritePrivateProfileStringWrapper(pProfile, pszSection, pszEntry, nullptr); } bRet = releaseProfile(pProfile); @@ -673,10 +745,7 @@ sal_uInt32 SAL_CALL osl_getProfileSectionEntries(oslProfile Profile, const sal_C } else { - ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - - WideCharToMultiByte(CP_ACP,0, reinterpret_cast<LPCWSTR>(pProfile->m_strFileName->buffer), -1, aFileName, aFileName.getBufSizeInSymbols(), nullptr, nullptr); - n = GetPrivateProfileString(pszSection, nullptr, nullptr, pszBuffer, MaxLen, aFileName); + n = GetPrivateProfileStringWrapper(pProfile, pszSection, nullptr, pszBuffer, MaxLen, nullptr); } releaseProfile(pProfile); @@ -828,7 +897,7 @@ bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, rtl else if ((rtl_ustr_ascii_compare_WithLength(pPath, RTL_CONSTASCII_LENGTH(STR_INI_METASYS), STR_INI_METASYS) == 0) && ((nLen == RTL_CONSTASCII_LENGTH(STR_INI_METASYS)) || (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METASYS)] == '/'))) { - if (((nPathLen = GetWindowsDirectoryW(::osl::mingw_reinterpret_cast<LPWSTR>(aPath), aPath.getBufSizeInSymbols())) == 0) || (nPathLen >= aPath.getBufSizeInSymbols())) + if (((nPathLen = GetWindowsDirectoryW(SAL_W(aPath), aPath.getBufSizeInSymbols())) == 0) || (nPathLen >= aPath.getBufSizeInSymbols())) return false; if (nLen > RTL_CONSTASCII_LENGTH(STR_INI_METASYS)) @@ -938,10 +1007,10 @@ sal_uInt32 SAL_CALL osl_getProfileSections(oslProfile Profile, sal_Char* pszBuff } else { - ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); + std::vector<wchar_t> aBuf(MaxLen + 1); + GetPrivateProfileSectionNamesW(&aBuf[0], MaxLen, SAL_W(rtl_uString_getStr(pProfile->m_strFileName))); - WideCharToMultiByte(CP_ACP,0, reinterpret_cast<LPCWSTR>(pProfile->m_strFileName->buffer), -1, aFileName, aFileName.getBufSizeInSymbols(), nullptr, nullptr); - n = GetPrivateProfileSectionNames(pszBuffer, MaxLen, aFileName); + n = WideCharToMultiByte(CP_ACP, 0, &aBuf[0], -1, pszBuffer, MaxLen, nullptr, nullptr); } releaseProfile(pProfile); @@ -1007,7 +1076,7 @@ static osl_TFile* openFileImpl(rtl_uString * strFileName, oslProfileOption Profi if (! bWriteable) { - pFile->m_Handle = CreateFileW( reinterpret_cast<LPCWSTR>(rtl_uString_getStr( strFileName )), GENERIC_READ, + pFile->m_Handle = CreateFileW( SAL_W(rtl_uString_getStr( strFileName )), GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr); @@ -1020,7 +1089,7 @@ static osl_TFile* openFileImpl(rtl_uString * strFileName, oslProfileOption Profi SAL_INFO("sal.osl", "opening read/write " << pszFilename); #endif - if ((pFile->m_Handle = CreateFileW( reinterpret_cast<LPCWSTR>(rtl_uString_getStr( strFileName )), GENERIC_READ | GENERIC_WRITE, + if ((pFile->m_Handle = CreateFileW( SAL_W(rtl_uString_getStr( strFileName )), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr)) == INVALID_HANDLE_VALUE) @@ -1750,13 +1819,13 @@ static bool osl_ProfileSwapProfileNames(osl_TProfileImpl* pProfile) ustrExtension=nullptr; /* unlink bak */ - DeleteFileW( reinterpret_cast<LPCWSTR>(rtl_uString_getStr( ustrBakFile )) ); + DeleteFileW( SAL_W(rtl_uString_getStr( ustrBakFile )) ); /* rename ini bak */ - MoveFileExW( reinterpret_cast<LPCWSTR>(rtl_uString_getStr( ustrIniFile )), reinterpret_cast<LPCWSTR>(rtl_uString_getStr( ustrBakFile )), MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH ); + MoveFileExW( SAL_W(rtl_uString_getStr( ustrIniFile )), SAL_W(rtl_uString_getStr( ustrBakFile )), MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH ); /* rename tmp ini */ - MoveFileExW( reinterpret_cast<LPCWSTR>(rtl_uString_getStr( ustrTmpFile )), reinterpret_cast<LPCWSTR>(rtl_uString_getStr( ustrIniFile )), MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH ); + MoveFileExW( SAL_W(rtl_uString_getStr( ustrTmpFile )), SAL_W(rtl_uString_getStr( ustrIniFile )), MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH ); return false; } diff --git a/sal/osl/w32/socket.cxx b/sal/osl/w32/socket.cxx index 97c8ffee2987..6cd8c8efe244 100644 --- a/sal/osl/w32/socket.cxx +++ b/sal/osl/w32/socket.cxx @@ -541,8 +541,7 @@ oslHostAddr SAL_CALL osl_createHostAddrByAddr(const oslSocketAddr pAddr) { oslHostAddr pRet = static_cast<oslHostAddr>( rtl_allocateZeroMemory(sizeof(struct oslHostAddrImpl))); - rtl_uString_newFromStr(&pRet->pHostName, - reinterpret_cast<sal_Unicode*>(&buf)); + rtl_uString_newFromStr(&pRet->pHostName, SAL_U(buf)); pRet->pSockAddr = createSocketAddr(); memcpy(& pRet->pSockAddr->m_sockaddr, & pAddr->m_sockaddr, sizeof(struct sockaddr)); @@ -1603,7 +1602,7 @@ void SAL_CALL osl_getLastSocketErrorDescription ( { sal_Unicode message[128]; - wsprintfW(reinterpret_cast<LPWSTR>(message), L"Unknown WinSock Error Number %d", error); + wsprintfW(SAL_W(message), L"Unknown WinSock Error Number %d", error); rtl_uString_newFromStr (strError, message); } diff --git a/sal/osl/w32/tempfile.cxx b/sal/osl/w32/tempfile.cxx index d765bd843e6b..f59107214aa4 100644 --- a/sal/osl/w32/tempfile.cxx +++ b/sal/osl/w32/tempfile.cxx @@ -95,7 +95,7 @@ static oslFileError osl_win32_GetTempFileName_impl_( oslFileError osl_error = osl_File_E_None; if (GetTempFileNameW( - reinterpret_cast<LPCWSTR>(rtl_uString_getStr(base_directory)), + SAL_W(rtl_uString_getStr(base_directory)), L"", 0, temp_file_name) == 0) @@ -157,7 +157,7 @@ static oslFileError osl_createTempFile_impl_( if ((osl_error == osl_File_E_None) && !b_delete_on_close) { rtl_uString* pustr = nullptr; - rtl_uString_newFromStr(&pustr, reinterpret_cast<const sal_Unicode*>(tmp_name)); + rtl_uString_newFromStr(&pustr, SAL_U(tmp_name)); osl_getFileURLFromSystemPath(pustr, ppustrTempFileURL); rtl_uString_release(pustr); } @@ -211,7 +211,7 @@ oslFileError SAL_CALL osl_createTempFile( oslFileError SAL_CALL osl_getTempDirURL(rtl_uString** pustrTempDir) { ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); - LPWSTR lpBuffer = ::osl::mingw_reinterpret_cast<LPWSTR>(aBuffer); + LPWSTR lpBuffer = SAL_W(aBuffer); DWORD nBufferLength = aBuffer.getBufSizeInSymbols() - 1; DWORD nLength; @@ -231,7 +231,7 @@ oslFileError SAL_CALL osl_getTempDirURL(rtl_uString** pustrTempDir) if ( '\\' == lpBuffer[nLength-1] ) lpBuffer[nLength-1] = 0; - rtl_uString_newFromStr( &ustrTempPath, reinterpret_cast<const sal_Unicode*>(lpBuffer) ); + rtl_uString_newFromStr( &ustrTempPath, SAL_U(lpBuffer) ); error = osl_getFileURLFromSystemPath( ustrTempPath, pustrTempDir ); diff --git a/sal/qa/osl/security/osl_Security.cxx b/sal/qa/osl/security/osl_Security.cxx index c1268b256bc6..90502118cfed 100644 --- a/sal/qa/osl/security/osl_Security.cxx +++ b/sal/qa/osl/security/osl_Security.cxx @@ -360,38 +360,40 @@ void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *, /// some initialization work for Windows OS /// Get the user name, computer name, user home directory. - LPTSTR lpszSystemInfo; // pointer to system information string + LPWSTR lpszSystemInfo; // pointer to system information string DWORD cchBuff = BUFSIZE; // size of computer or user name - TCHAR tchBuffer[BUFSIZE]; // buffer for string + WCHAR wchBuffer[BUFSIZE]; // buffer for string - lpszSystemInfo = tchBuffer; - if( GetUserNameA(lpszSystemInfo, &cchBuff) ) - strUserName = ::rtl::OUString::createFromAscii( lpszSystemInfo ); + lpszSystemInfo = wchBuffer; + if( GetUserNameW(lpszSystemInfo, &cchBuff) ) + strUserName = SAL_U(lpszSystemInfo); - if( GetComputerName(lpszSystemInfo, &cchBuff) ) - strComputerName = ::rtl::OUString::createFromAscii( lpszSystemInfo ); + cchBuff = BUFSIZE; + if( GetComputerNameW(lpszSystemInfo, &cchBuff) ) + strComputerName = SAL_U(lpszSystemInfo); /// Get user home directory. HKEY hRegKey; - sal_Char PathA[_MAX_PATH]; - if (RegOpenKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &hRegKey) == ERROR_SUCCESS) + if (RegOpenKeyW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", &hRegKey) == ERROR_SUCCESS) { - LONG lRet; - DWORD lSize = sizeof(PathA); + sal_Unicode PathW[_MAX_PATH]; + LSTATUS lRet; + DWORD lSize = sizeof(PathW); DWORD Type; - lRet = RegQueryValueEx(hRegKey, "AppData", nullptr, &Type, reinterpret_cast<unsigned char *>(PathA), &lSize); - if ( ( lRet == ERROR_SUCCESS ) && ( Type == REG_SZ ) && ( _access( PathA, 0 ) == 0 ) ) + lRet = RegQueryValueExW(hRegKey, L"AppData", nullptr, &Type, reinterpret_cast<unsigned char *>(PathW), &lSize); + if ( ( lRet == ERROR_SUCCESS ) && ( Type == REG_SZ ) && ( _waccess( SAL_W(PathW), 0 ) == 0 ) ) { CPPUNIT_ASSERT_EQUAL_MESSAGE( "#Convert from system path to URL failed.", - ::osl::File::E_None, ::osl::File::getFileURLFromSystemPath( ::rtl::OUString::createFromAscii( PathA ), strConfigDirectory ) ); + ::osl::File::E_None, ::osl::File::getFileURLFromSystemPath( PathW, strConfigDirectory ) ); } - lRet = RegQueryValueEx(hRegKey, "Personal", nullptr, &Type, reinterpret_cast<unsigned char *>(PathA), &lSize); - if ( ( lRet == ERROR_SUCCESS ) && ( Type == REG_SZ ) && ( _access( PathA, 0 ) == 0 ) ) + lSize = sizeof(PathW); + lRet = RegQueryValueExW(hRegKey, L"Personal", nullptr, &Type, reinterpret_cast<unsigned char *>(PathW), &lSize); + if ( ( lRet == ERROR_SUCCESS ) && ( Type == REG_SZ ) && ( _waccess( SAL_W(PathW), 0 ) == 0 ) ) { CPPUNIT_ASSERT_EQUAL_MESSAGE( "#Convert from system path to URL failed.", - ::osl::File::E_None, ::osl::File::getFileURLFromSystemPath( ::rtl::OUString::createFromAscii( PathA ), strHomeDirectory ) ); + ::osl::File::E_None, ::osl::File::getFileURLFromSystemPath( PathW, strHomeDirectory ) ); } RegCloseKey(hRegKey); @@ -479,7 +481,7 @@ void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *, DWORD dwSidRev=SID_REVISION; DWORD dwCounter; DWORD dwSidSize; - sal_Char *Ident; + wchar_t *Ident; /* obtain SidIdentifierAuthority */ psia=GetSidIdentifierAuthority(pSid); @@ -488,16 +490,16 @@ void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *, dwSubAuthorities=std::min((int) *GetSidSubAuthorityCount(pSid), 5); /* buffer length: S-SID_REVISION- + identifierauthority- + subauthorities- + NULL */ - Ident=static_cast<sal_Char *>(malloc(88*sizeof(sal_Char))); + Ident=static_cast<wchar_t *>(malloc(88*sizeof(wchar_t))); /* prepare S-SID_REVISION- */ - dwSidSize=wsprintf(Ident, TEXT("S-%lu-"), dwSidRev); + dwSidSize=wsprintfW(Ident, L"S-%lu-", dwSidRev); /* prepare SidIdentifierAuthority */ if ((psia->Value[0] != 0) || (psia->Value[1] != 0)) { - dwSidSize+=wsprintf(Ident + strlen(Ident), - TEXT("0x%02hx%02hx%02hx%02hx%02hx%02hx"), + dwSidSize+=wsprintfW(Ident + wcslen(Ident), + L"0x%02hx%02hx%02hx%02hx%02hx%02hx", (sal_uInt16)psia->Value[0], (sal_uInt16)psia->Value[1], (sal_uInt16)psia->Value[2], @@ -507,8 +509,8 @@ void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *, } else { - dwSidSize+=wsprintf(Ident + strlen(Ident), - TEXT("%lu"), + dwSidSize+=wsprintfW(Ident + wcslen(Ident), + L"%lu", (sal_uInt32)(psia->Value[5] ) + (sal_uInt32)(psia->Value[4] << 8) + (sal_uInt32)(psia->Value[3] << 16) + @@ -518,11 +520,11 @@ void MyTestPlugInImpl::initialize( CPPUNIT_NS::TestFactoryRegistry *, /* loop through SidSubAuthorities */ for (dwCounter=0; dwCounter < dwSubAuthorities; dwCounter++) { - dwSidSize+=wsprintf(Ident + dwSidSize, TEXT("-%lu"), + dwSidSize+=wsprintfW(Ident + dwSidSize, L"-%lu", *GetSidSubAuthority(pSid, dwCounter) ); } - strUserID = ::rtl::OUString::createFromAscii( Ident ); + strUserID = SAL_U(Ident); free(Ident); delete [] static_cast<BYTE*>(pSid); diff --git a/sal/rtl/alloc_cache.cxx b/sal/rtl/alloc_cache.cxx index 4ac83d332eab..18785795a2ad 100644 --- a/sal/rtl/alloc_cache.cxx +++ b/sal/rtl/alloc_cache.cxx @@ -1223,7 +1223,7 @@ static void rtl_cache_wsupdate_init() RTL_MEMORY_LOCK_ACQUIRE(&(g_cache_list.m_lock)); g_cache_list.m_update_done = 0; - g_cache_list.m_update_cond = CreateEvent (nullptr, TRUE, FALSE, nullptr); + g_cache_list.m_update_cond = CreateEventW (nullptr, TRUE, FALSE, nullptr); g_cache_list.m_update_thread = CreateThread (nullptr, 0, rtl_cache_wsupdate_all, reinterpret_cast<LPVOID>(10), 0, &dwThreadId); |