diff options
author | Mikhail Voytenko <mav@openoffice.org> | 2010-01-29 16:56:48 +0100 |
---|---|---|
committer | Mikhail Voytenko <mav@openoffice.org> | 2010-01-29 16:56:48 +0100 |
commit | 5ba32a9abf26e7cb37f7ff3280a230dbf2bd5952 (patch) | |
tree | e8ec74344b664271bbb44a5eebd9570b48e97673 /sal/osl/w32 | |
parent | 066fd012867ceb64fb05f79b3e82ba353ac6d418 (diff) |
#i50885# let some files support C++ syntax and use dynamic memory for long pathes
Diffstat (limited to 'sal/osl/w32')
-rw-r--r-- | sal/osl/w32/file_dirvol.cxx | 25 | ||||
-rw-r--r-- | sal/osl/w32/file_url.cxx | 136 | ||||
-rw-r--r-- | sal/osl/w32/module.cxx (renamed from sal/osl/w32/module.c) | 18 | ||||
-rw-r--r-- | sal/osl/w32/path_helper.hxx | 37 | ||||
-rw-r--r-- | sal/osl/w32/process.cxx (renamed from sal/osl/w32/process.c) | 31 | ||||
-rw-r--r-- | sal/osl/w32/profile.cxx (renamed from sal/osl/w32/profile.c) | 245 | ||||
-rw-r--r-- | sal/osl/w32/signal.cxx (renamed from sal/osl/w32/signal.c) | 15 | ||||
-rw-r--r-- | sal/osl/w32/tempfile.cxx | 26 |
8 files changed, 280 insertions, 253 deletions
diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx index df2919143b18..22e2c7f2d5d9 100644 --- a/sal/osl/w32/file_dirvol.cxx +++ b/sal/osl/w32/file_dirvol.cxx @@ -37,6 +37,7 @@ #include "file_url.h" #include "file_error.h" + #include "path_helper.hxx" #include "osl/diagnose.h" @@ -675,13 +676,13 @@ static DWORD create_dir_with_callback( else { /* the long urls can not contain ".." while calling CreateDirectory, no idea why! */ - sal_Unicode pBuf[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Unicode > aBuf( MAX_LONG_PATH ); sal_uInt32 nNewLen = GetCaseCorrectPathName( reinterpret_cast<LPCTSTR>( rtl_uString_getStr( dir_path ) ), - pBuf, - MAX_LONG_PATH, + aBuf, + aBuf.getBufSizeInSymbols(), sal_False ); - bCreated = CreateDirectoryW( pBuf, NULL ); + bCreated = CreateDirectoryW( aBuf, NULL ); } if ( bCreated ) @@ -790,13 +791,13 @@ oslFileError SAL_CALL osl_createDirectory(rtl_uString* strPath) else { /* the long urls can not contain ".." while calling CreateDirectory, no idea why! */ - sal_Unicode pBuf[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Unicode > aBuf( MAX_LONG_PATH ); sal_uInt32 nNewLen = GetCaseCorrectPathName( reinterpret_cast<LPCTSTR>( rtl_uString_getStr( strSysPath ) ), - pBuf, - MAX_LONG_PATH, + aBuf, + aBuf.getBufSizeInSymbols(), sal_False ); - bCreated = CreateDirectoryW( pBuf, NULL ); + bCreated = CreateDirectoryW( aBuf, NULL ); } @@ -1785,15 +1786,15 @@ oslFileError SAL_CALL osl_getFileStatus( if ( !pItemImpl->bFullPathNormalized ) { sal_uInt32 nLen = rtl_uString_getLength( pItemImpl->m_pFullPath ); - sal_Unicode pBuffer[ MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); sal_uInt32 nNewLen = GetCaseCorrectPathName( reinterpret_cast<LPCTSTR>( rtl_uString_getStr( pItemImpl->m_pFullPath ) ), - pBuffer, - MAX_LONG_PATH, + aBuffer, + aBuffer.getBufSizeInSymbols(), sal_True ); if ( nNewLen ) { - rtl_uString_newFromStr( &pItemImpl->m_pFullPath, reinterpret_cast< const sal_Unicode* >( pBuffer ) ); + rtl_uString_newFromStr( &pItemImpl->m_pFullPath, aBuffer ); pItemImpl->bFullPathNormalized = TRUE; } } diff --git a/sal/osl/w32/file_url.cxx b/sal/osl/w32/file_url.cxx index 3e40ab0fb28a..2cd1dfa1b5a1 100644 --- a/sal/osl/w32/file_url.cxx +++ b/sal/osl/w32/file_url.cxx @@ -41,6 +41,8 @@ #include "osl/file.h" #include "osl/mutex.h" +#include "path_helper.hxx" + #include <stdio.h> #include <tchar.h> @@ -403,32 +405,39 @@ DWORD IsValidFilePath(rtl_uString *path, LPCTSTR *lppError, DWORD dwFlags, rtl_u } //##################################################### -static BOOL PathRemoveFileSpec(LPTSTR lpPath, LPTSTR lpFileName ) +static sal_Int32 PathRemoveFileSpec(LPTSTR lpPath, LPTSTR lpFileName, sal_Int32 nFileBufLen ) { - BOOL fSuccess = FALSE; // Assume failure - LPTSTR lpLastBkSlash = _tcsrchr( lpPath, '\\' ); - LPTSTR lpLastSlash = _tcsrchr( lpPath, '/' ); - LPTSTR lpLastDelimiter = lpLastSlash > lpLastBkSlash ? lpLastSlash : lpLastBkSlash; + sal_Int32 nRemoved = 0; - if ( lpLastDelimiter ) + if ( nFileBufLen ) { - if ( 0 == *(lpLastDelimiter + 1) ) - { - if ( lpLastDelimiter > lpPath && *(lpLastDelimiter - 1) != ':' ) + lpFileName[0] = 0; + LPTSTR lpLastBkSlash = _tcsrchr( lpPath, '\\' ); + LPTSTR lpLastSlash = _tcsrchr( lpPath, '/' ); + LPTSTR lpLastDelimiter = lpLastSlash > lpLastBkSlash ? lpLastSlash : lpLastBkSlash; + + if ( lpLastDelimiter ) + { + sal_Int32 nDelLen = _tcslen( lpLastDelimiter ); + if ( 1 == nDelLen ) { - *lpLastDelimiter = 0; - *lpFileName = 0; - fSuccess = TRUE; + if ( lpLastDelimiter > lpPath && *(lpLastDelimiter - 1) != ':' ) + { + *lpLastDelimiter = 0; + *lpFileName = 0; + nRemoved = nDelLen; + } } - } - else - { - _tcscpy( lpFileName, lpLastDelimiter + 1 ); - *(++lpLastDelimiter) = 0; - fSuccess = TRUE; - } + else if ( nDelLen && nDelLen - 1 < nFileBufLen ) + { + _tcscpy( lpFileName, lpLastDelimiter + 1 ); + *(++lpLastDelimiter) = 0; + nRemoved = nDelLen - 1; + } + } } - return fSuccess; + + return nRemoved; } //##################################################### @@ -454,38 +463,31 @@ static LPTSTR PathAddBackslash(LPTSTR lpPath, sal_Int32 nBufLen) //##################################################### // Same as GetLongPathName but also 95/NT4 static DWORD GetCaseCorrectPathNameEx( - LPCTSTR lpszShortPath, // file name - LPTSTR lpszLongPath, // path buffer + LPTSTR lpszPath, // path buffer to convert DWORD cchBuffer, // size of path buffer DWORD nSkipLevels, BOOL bCheckExistence ) { - TCHAR szPath[MAX_LONG_PATH]; - TCHAR szFile[MAX_LONG_PATH]; /* MAX_LONG_PATH is used here for the case of invalid long file names */ - BOOL fSuccess; - - cchBuffer = cchBuffer; /* avoid warnings */ - - _tcscpy( szPath, lpszShortPath ); - - fSuccess = PathRemoveFileSpec( szPath, szFile ); + ::osl::LongPathBuffer< sal_Unicode > szFile( MAX_PATH + 1 ); + sal_Int32 nRemoved = PathRemoveFileSpec( lpszPath, szFile, MAX_PATH + 1 ); + sal_Int32 nLastStepRemoved = nRemoved; + while ( nLastStepRemoved && szFile[0] == 0 ) + { + // remove separators + nLastStepRemoved = PathRemoveFileSpec( lpszPath, szFile, MAX_PATH + 1 ); + nRemoved += nLastStepRemoved; + } - if ( fSuccess ) + if ( nRemoved ) { - int nLen = _tcslen( szPath ); - LPCTSTR lpszFileSpec = lpszShortPath + nLen; - BOOL bSkipThis; + BOOL bSkipThis = FALSE; - if ( 0 == _tcscmp( lpszFileSpec, TEXT("..") ) ) + if ( 0 == _tcscmp( szFile, TEXT("..") ) ) { bSkipThis = TRUE; nSkipLevels += 1; } - else if ( - 0 == _tcscmp( lpszFileSpec, TEXT(".") ) || - 0 == _tcscmp( lpszFileSpec, TEXT("\\") ) || - 0 == _tcscmp( lpszFileSpec, TEXT("/") ) - ) + else if ( 0 == _tcscmp( szFile, TEXT(".") ) ) { bSkipThis = TRUE; } @@ -497,31 +499,35 @@ static DWORD GetCaseCorrectPathNameEx( else bSkipThis = FALSE; - GetCaseCorrectPathNameEx( szPath, szPath, MAX_LONG_PATH, nSkipLevels, bCheckExistence ); + GetCaseCorrectPathNameEx( lpszPath, cchBuffer, nSkipLevels, bCheckExistence ); - PathAddBackslash( szPath, ELEMENTS_OF_ARRAY( szPath ) ); + PathAddBackslash( lpszPath, cchBuffer ); /* Analyze parent if not only a trailing backslash was cutted but a real file spec */ if ( !bSkipThis ) { if ( bCheckExistence ) { + ::osl::LongPathBuffer< sal_Unicode > aShortPath( MAX_LONG_PATH ); + _tcscpy( aShortPath, lpszPath ); + _tcscat( aShortPath, szFile ); + WIN32_FIND_DATA aFindFileData; - HANDLE hFind = FindFirstFile( lpszShortPath, &aFindFileData ); + HANDLE hFind = FindFirstFile( aShortPath, &aFindFileData ); if ( IsValidHandle(hFind) ) { - _tcscat( szPath, aFindFileData.cFileName[0] ? aFindFileData.cFileName : aFindFileData.cAlternateFileName ); + _tcscat( lpszPath, aFindFileData.cFileName[0] ? aFindFileData.cFileName : aFindFileData.cAlternateFileName ); FindClose( hFind ); } else - return 0; + lpszPath[0] = 0; } else { /* add the segment name back */ - _tcscat( szPath, szFile ); + _tcscat( lpszPath, szFile ); } } } @@ -531,14 +537,14 @@ static DWORD GetCaseCorrectPathNameEx( or a network share. If still levels to skip are left, the path specification tries to travel below the file system root */ if ( nSkipLevels ) - return 0; - - _tcsupr( szPath ); + lpszPath[0] = 0; + else + _tcsupr( lpszPath ); } - _tcscpy( lpszLongPath, szPath ); + rtl_freeMemory( szFile ); - return _tcslen( lpszLongPath ); + return _tcslen( lpszPath ); } //##################################################### @@ -564,10 +570,16 @@ DWORD GetCaseCorrectPathName( return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1; } } - else + else if ( lpszShortPath ) { - return GetCaseCorrectPathNameEx( lpszShortPath, lpszLongPath, cchBuffer, 0, bCheckExistence ); + if ( _tcslen( lpszShortPath ) <= cchBuffer ) + { + _tcscpy( lpszLongPath, lpszShortPath ); + return GetCaseCorrectPathNameEx( lpszLongPath, cchBuffer, 0, bCheckExistence ); + } } + + return 0; } @@ -1063,8 +1075,8 @@ oslFileError SAL_CALL osl_getAbsoluteFileURL( rtl_uString* ustrBaseURL, rtl_uStr if ( !eError ) { - TCHAR szBuffer[MAX_LONG_PATH]; - TCHAR szCurrentDir[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + ::osl::LongPathBuffer< sal_Unicode > aCurrentDir( MAX_LONG_PATH ); LPTSTR lpFilePart = NULL; DWORD dwResult; @@ -1079,28 +1091,28 @@ oslFileError SAL_CALL osl_getAbsoluteFileURL( rtl_uString* ustrBaseURL, rtl_uStr { osl_acquireMutex( g_CurrentDirectoryMutex ); - GetCurrentDirectory( MAX_LONG_PATH, szCurrentDir ); - SetCurrentDirectory( reinterpret_cast<LPCTSTR>(ustrBaseSysPath->buffer) ); + GetCurrentDirectoryW( aCurrentDir.getBufSizeInSymbols(), aCurrentDir ); + SetCurrentDirectoryW( reinterpret_cast<LPCTSTR>(ustrBaseSysPath->buffer) ); } - dwResult = GetFullPathName( reinterpret_cast<LPCTSTR>(ustrRelSysPath->buffer), MAX_LONG_PATH, szBuffer, &lpFilePart ); + dwResult = GetFullPathNameW( reinterpret_cast<LPCTSTR>(ustrRelSysPath->buffer), aBuffer.getBufSizeInSymbols(), aBuffer, &lpFilePart ); if ( ustrBaseSysPath ) { - SetCurrentDirectory( szCurrentDir ); + SetCurrentDirectoryW( aCurrentDir ); osl_releaseMutex( g_CurrentDirectoryMutex ); } if ( dwResult ) { - if ( dwResult >= MAX_LONG_PATH ) + if ( dwResult >= aBuffer.getBufSizeInSymbols() ) eError = osl_File_E_INVAL; else { rtl_uString *ustrAbsSysPath = NULL; - rtl_uString_newFromStr( &ustrAbsSysPath, reinterpret_cast<const sal_Unicode*>(szBuffer) ); + rtl_uString_newFromStr( &ustrAbsSysPath, aBuffer ); eError = osl_getFileURLFromSystemPath( ustrAbsSysPath, pustrAbsoluteURL ); diff --git a/sal/osl/w32/module.c b/sal/osl/w32/module.cxx index f4e62b525631..57711e973b73 100644 --- a/sal/osl/w32/module.c +++ b/sal/osl/w32/module.cxx @@ -33,12 +33,14 @@ #include <tlhelp32.h> #include "file_url.h" +#include "path_helper.hxx" #include <osl/module.h> #include <osl/diagnose.h> #include <osl/thread.h> #include <osl/file.h> #include <rtl/logfile.h> + /* under WIN32, we use the void* oslModule as a WIN32 HANDLE (which is also a 32-bit value) @@ -314,22 +316,22 @@ static sal_Bool SAL_CALL _osl_addressGetModuleURL_NT4( void *pv, rtl_uString **p if ( lpfnSymInitialize && lpfnSymCleanup && lpfnSymGetModuleInfo ) { IMAGEHLP_MODULE ModuleInfo; - CHAR szModuleFileName[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Char > aModuleFileName( MAX_LONG_PATH ); LPSTR lpSearchPath = NULL; - if ( GetModuleFileNameA( NULL, szModuleFileName, sizeof(szModuleFileName) ) ) + if ( GetModuleFileNameA( NULL, aModuleFileName, aModuleFileName.getBufSizeInSymbols() ) ) { - char *pLastBkSlash = strrchr( szModuleFileName, '\\' ); + char *pLastBkSlash = strrchr( aModuleFileName, '\\' ); if ( pLastBkSlash && - pLastBkSlash > szModuleFileName + pLastBkSlash > (sal_Char*)aModuleFileName && *(pLastBkSlash - 1) != ':' && *(pLastBkSlash - 1) != '\\' ) { *pLastBkSlash = 0; - lpSearchPath = szModuleFileName; + lpSearchPath = aModuleFileName; } } @@ -428,12 +430,12 @@ static sal_Bool SAL_CALL _osl_addressGetModuleURL_NT( void *pv, rtl_uString **pu if ( (BYTE *)pv >= (BYTE *)modinfo.lpBaseOfDll && (BYTE *)pv < (BYTE *)modinfo.lpBaseOfDll + modinfo.SizeOfImage ) { - WCHAR szBuffer[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); rtl_uString *ustrSysPath = NULL; - GetModuleFileNameW( lpModules[iModule], szBuffer, bufsizeof(szBuffer) ); + GetModuleFileNameW( lpModules[iModule], aBuffer, aBuffer.getBufSizeInSymbols() ); - rtl_uString_newFromStr( &ustrSysPath, szBuffer ); + rtl_uString_newFromStr( &ustrSysPath, aBuffer ); osl_getFileURLFromSystemPath( ustrSysPath, pustrURL ); rtl_uString_release( ustrSysPath ); diff --git a/sal/osl/w32/path_helper.hxx b/sal/osl/w32/path_helper.hxx index 289f77c8db78..bc2edafbf7d5 100644 --- a/sal/osl/w32/path_helper.hxx +++ b/sal/osl/w32/path_helper.hxx @@ -37,6 +37,7 @@ #include "path_helper.h" #include <rtl/ustring.hxx> +#include <rtl/allocator.hxx> namespace osl { @@ -73,6 +74,42 @@ inline bool systemPathIsLogicalDrivePattern(/*in*/ const rtl::OUString& path) return osl_systemPathIsLogicalDrivePattern(path.pData); } +/******************************************************************* + LongPathBuffer + ******************************************************************/ +template< class T > +class LongPathBuffer +{ + T* m_pBuffer; + sal_uInt32 m_nCharNum; + + LongPathBuffer(); + LongPathBuffer( const LongPathBuffer& ); + LongPathBuffer& operator=( const LongPathBuffer& ); + +public: + LongPathBuffer( sal_uInt32 nCharNum ) + : m_pBuffer( reinterpret_cast<T*>( rtl_allocateMemory( nCharNum * sizeof( T ) ) ) ) + , m_nCharNum( nCharNum ) + {} + + ~LongPathBuffer() + { + rtl_freeMemory( m_pBuffer ); + m_pBuffer = 0; + } + + sal_uInt32 getBufSizeInSymbols() + { + return m_nCharNum; + } + + operator T* () + { + return m_pBuffer; + } +}; + } // end namespace osl #endif diff --git a/sal/osl/w32/process.c b/sal/osl/w32/process.cxx index e14915f2590f..bbcb5109778f 100644 --- a/sal/osl/w32/process.c +++ b/sal/osl/w32/process.cxx @@ -47,6 +47,7 @@ #include "procimpl.h" #include "sockimpl.h" #include "file_url.h" +#include "path_helper.hxx" #include <rtl/ustrbuf.h> #include <rtl/alloc.h> @@ -76,7 +77,7 @@ oslProcess SAL_CALL osl_getProcess(oslProcessIdentifier Ident) if (hProcess) { - pProcImpl = rtl_allocateMemory(sizeof(oslProcessImpl)); + pProcImpl = reinterpret_cast< oslProcessImpl*>( rtl_allocateMemory(sizeof(oslProcessImpl)) ); pProcImpl->m_hProcess = hProcess; pProcImpl->m_IdProcess = Ident; } @@ -226,13 +227,13 @@ oslProcessError SAL_CALL osl_bootstrap_getExecutableFile_Impl ( { oslProcessError result = osl_Process_E_NotFound; - TCHAR buffer[MAX_LONG_PATH]; - DWORD buflen; + ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + DWORD buflen = 0; - if ((buflen = GetModuleFileNameW (0, buffer, MAX_LONG_PATH)) > 0) + if ((buflen = GetModuleFileNameW (0, aBuffer, aBuffer.getBufSizeInSymbols())) > 0) { rtl_uString * pAbsPath = 0; - rtl_uString_newFromStr_WithLength (&(pAbsPath), buffer, buflen); + rtl_uString_newFromStr_WithLength (&(pAbsPath), aBuffer, buflen); if (pAbsPath) { /* Convert from path to url. */ @@ -286,16 +287,16 @@ static rtl_uString ** osl_createCommandArgs_Impl (int argc, char ** argv) if (ppArgs[0] != 0) { /* Ensure absolute path */ - DWORD dwResult; - TCHAR szBuffer[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + DWORD dwResult = 0; dwResult = SearchPath ( - 0, ppArgs[0]->buffer, L".exe", MAX_LONG_PATH, szBuffer, 0); - if ((0 < dwResult) && (dwResult < MAX_LONG_PATH)) + 0, ppArgs[0]->buffer, L".exe", aBuffer.getBufSizeInSymbols(), aBuffer, 0); + if ((0 < dwResult) && (dwResult < aBuffer.getBufSizeInSymbols())) { /* Replace argv[0] with it's absolute path */ rtl_uString_newFromStr_WithLength( - &(ppArgs[0]), szBuffer, dwResult); + &(ppArgs[0]), aBuffer, dwResult); } } if (ppArgs[0] != 0) @@ -419,20 +420,20 @@ extern oslMutex g_CurrentDirectoryMutex; oslProcessError SAL_CALL osl_getProcessWorkingDir( rtl_uString **pustrWorkingDir ) { - TCHAR szBuffer[MAX_LONG_PATH]; - DWORD dwLen; + ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + DWORD dwLen = 0; osl_acquireMutex( g_CurrentDirectoryMutex ); - dwLen = GetCurrentDirectory( sizeof(szBuffer) / sizeof(TCHAR), szBuffer ); + dwLen = GetCurrentDirectory( aBuffer.getBufSizeInSymbols(), aBuffer ); osl_releaseMutex( g_CurrentDirectoryMutex ); - if ( dwLen ) + if ( dwLen && dwLen < aBuffer.getBufSizeInSymbols() ) { oslFileError eError; rtl_uString *ustrTemp = NULL;; - rtl_uString_newFromStr_WithLength( &ustrTemp, szBuffer, dwLen ); + rtl_uString_newFromStr_WithLength( &ustrTemp, aBuffer, dwLen ); eError = osl_getFileURLFromSystemPath( ustrTemp, pustrWorkingDir ); rtl_uString_release( ustrTemp ); diff --git a/sal/osl/w32/profile.c b/sal/osl/w32/profile.cxx index 219669779f01..583faeac90ef 100644 --- a/sal/osl/w32/profile.c +++ b/sal/osl/w32/profile.cxx @@ -32,6 +32,7 @@ #include "system.h" #include "file_url.h" +#include "path_helper.hxx" #include <osl/diagnose.h> #include <osl/profile.h> @@ -504,10 +505,10 @@ sal_Bool SAL_CALL osl_readProfileString(oslProfile Profile, } else { - CHAR szFileName[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_LONG_PATH, NULL, NULL); - GetPrivateProfileString(pszSection, pszEntry, pszDefault, pszString, MaxLen, szFileName); + WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, aFileName, aFileName.getBufSizeInSymbols(), NULL, NULL); + GetPrivateProfileString(pszSection, pszEntry, pszDefault, pszString, MaxLen, aFileName); } releaseProfile(pProfile); @@ -685,10 +686,10 @@ sal_Bool SAL_CALL osl_writeProfileString(oslProfile Profile, } else { - CHAR szFileName[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_LONG_PATH, NULL, NULL); - WritePrivateProfileString(pszSection, pszEntry, pszString, szFileName); + WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, aFileName, aFileName.getBufSizeInSymbols(), NULL, NULL); + WritePrivateProfileString(pszSection, pszEntry, pszString, aFileName); } bRet = releaseProfile(pProfile); @@ -796,10 +797,10 @@ sal_Bool SAL_CALL osl_removeProfileEntry(oslProfile Profile, } else { - CHAR szFileName[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_LONG_PATH, NULL, NULL); - WritePrivateProfileString(pszSection, pszEntry, NULL, szFileName); + WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, aFileName, aFileName.getBufSizeInSymbols(), NULL, NULL); + WritePrivateProfileString(pszSection, pszEntry, NULL, aFileName); } bRet = releaseProfile(pProfile); @@ -870,10 +871,10 @@ sal_uInt32 SAL_CALL osl_getProfileSectionEntries(oslProfile Profile, const sal_C } else { - CHAR szFileName[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_LONG_PATH, NULL, NULL); - n = GetPrivateProfileString(pszSection, NULL, NULL, pszBuffer, MaxLen, szFileName); + WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, aFileName, aFileName.getBufSizeInSymbols(), NULL, NULL); + n = GetPrivateProfileString(pszSection, NULL, NULL, pszBuffer, MaxLen, aFileName); } releaseProfile(pProfile); @@ -889,9 +890,9 @@ sal_uInt32 SAL_CALL osl_getProfileSectionEntries(oslProfile Profile, const sal_C sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, rtl_uString** strProfileName) { sal_Bool bFailed; - sal_Unicode wcsFile[MAX_LONG_PATH]; - sal_Unicode wcsPath[MAX_LONG_PATH]; - sal_uInt32 nFileLen; + ::osl::LongPathBuffer< sal_Unicode > aFile( MAX_LONG_PATH ); + ::osl::LongPathBuffer< sal_Unicode > aPath( MAX_LONG_PATH ); + sal_uInt32 nFileLen = 0; sal_uInt32 nPathLen = 0; rtl_uString * strTmp = NULL; @@ -900,19 +901,19 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, /* build file name */ if (strName && strName->length) { - if(strName->length >= MAX_LONG_PATH) + if( ::sal::static_int_cast< sal_uInt32 >( strName->length ) >= aFile.getBufSizeInSymbols() ) return sal_False; - wcscpy(wcsFile, strName->buffer); + wcscpy( aFile, strName->buffer); nFileLen = strName->length; - if (rtl_ustr_indexOfChar( wcsFile, L'.' ) == -1) + if (rtl_ustr_indexOfChar( aFile, L'.' ) == -1) { - if (nFileLen + wcslen(STR_INI_EXTENSION) >= MAX_LONG_PATH) + if (nFileLen + wcslen(STR_INI_EXTENSION) >= aFile.getBufSizeInSymbols()) return sal_False; /* add default extension */ - wcscpy(wcsFile + nFileLen, STR_INI_EXTENSION); + wcscpy( aFile + nFileLen, STR_INI_EXTENSION); nFileLen += wcslen(STR_INI_EXTENSION); } } @@ -939,22 +940,22 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, if ((nPos = rtl_ustr_lastIndexOfChar( pProgName, L'.' )) != -1 ) nLen -= 4; - if ((nFileLen = nLen - nOffset) >= MAX_LONG_PATH) + if ((nFileLen = nLen - nOffset) >= aFile.getBufSizeInSymbols()) return sal_False; - wcsncpy(wcsFile, pProgName + nOffset, nFileLen); + wcsncpy(aFile, pProgName + nOffset, nFileLen); - if (nFileLen + wcslen(STR_INI_EXTENSION) >= MAX_LONG_PATH) + if (nFileLen + wcslen(STR_INI_EXTENSION) >= aFile.getBufSizeInSymbols()) return sal_False; /* add default extension */ - wcscpy(wcsFile + nFileLen, STR_INI_EXTENSION); + wcscpy(aFile + nFileLen, STR_INI_EXTENSION); nFileLen += wcslen(STR_INI_EXTENSION); rtl_uString_release( strProgName ); } - if (wcsFile[0] == 0) + if (aFile[0] == 0) return sal_False; /* build directory path */ @@ -974,10 +975,10 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, if (bFailed) return (sal_False); - if (strHome->length >= MAX_LONG_PATH) + if ( ::sal::static_int_cast< sal_uInt32 >( strHome->length ) >= aPath.getBufSizeInSymbols()) return sal_False; - wcscpy( wcsPath, strHome->buffer); + wcscpy( aPath, strHome->buffer); nPathLen = strHome->length; if (nLen > RTL_CONSTASCII_LENGTH(STR_INI_METAHOME)) @@ -985,10 +986,10 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, pPath += RTL_CONSTASCII_LENGTH(STR_INI_METAHOME); nLen -= RTL_CONSTASCII_LENGTH(STR_INI_METAHOME); - if (nLen + nPathLen >= MAX_LONG_PATH) + if (nLen + nPathLen >= aPath.getBufSizeInSymbols()) return sal_False; - wcscpy(wcsPath + nPathLen, pPath); + wcscpy(aPath + nPathLen, pPath); nPathLen += nLen; } @@ -1006,10 +1007,10 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, if (bFailed) return (sal_False); - if (strConfig->length >= MAX_LONG_PATH) + if ( ::sal::static_int_cast< sal_uInt32 >( strConfig->length ) >= aPath.getBufSizeInSymbols()) return sal_False; - wcscpy( wcsPath, strConfig->buffer); + wcscpy( aPath, strConfig->buffer); nPathLen = strConfig->length; if (nLen > RTL_CONSTASCII_LENGTH(STR_INI_METACFG)) @@ -1017,10 +1018,10 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, pPath += RTL_CONSTASCII_LENGTH(STR_INI_METACFG); nLen -= RTL_CONSTASCII_LENGTH(STR_INI_METACFG); - if (nLen + nPathLen >= MAX_LONG_PATH) + if (nLen + nPathLen >= aPath.getBufSizeInSymbols()) return sal_False; - wcscpy(wcsPath + nPathLen, pPath); + wcscpy(aPath + nPathLen, pPath); nPathLen += nLen; } @@ -1030,7 +1031,7 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, 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(wcsPath, MAX_LONG_PATH)) == 0) || (nPathLen >= MAX_LONG_PATH)) + if (((nPathLen = GetWindowsDirectoryW(aPath, aPath.getBufSizeInSymbols())) == 0) || (nPathLen >= aPath.getBufSizeInSymbols())) return (sal_False); if (nLen > RTL_CONSTASCII_LENGTH(STR_INI_METASYS)) @@ -1038,10 +1039,10 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, pPath += RTL_CONSTASCII_LENGTH(STR_INI_METASYS); nLen -= RTL_CONSTASCII_LENGTH(STR_INI_METASYS); - if (nLen + nPathLen >= MAX_LONG_PATH) + if (nLen + nPathLen >= aPath.getBufSizeInSymbols()) return sal_False; - wcscpy(wcsPath + nPathLen, pPath); + wcscpy(aPath + nPathLen, pPath); nPathLen += nLen; } } @@ -1050,16 +1051,16 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, ((nLen == RTL_CONSTASCII_LENGTH(STR_INI_METAINS)) || (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METAINS)] == '/') || (pPath[RTL_CONSTASCII_LENGTH(STR_INI_METAINS)] == '"') ) ) { - if (! lookupProfile(pPath + RTL_CONSTASCII_LENGTH(STR_INI_METAINS), wcsFile, wcsPath)) + if (! lookupProfile(pPath + RTL_CONSTASCII_LENGTH(STR_INI_METAINS), aFile, aPath)) return (sal_False); - nPathLen = wcslen(wcsPath); + nPathLen = wcslen(aPath); } - else if(nLen < MAX_LONG_PATH) + else if( ::sal::static_int_cast< sal_uInt32 >( nLen ) < aPath.getBufSizeInSymbols()) { - wcscpy(wcsPath, pPath); - nPathLen = wcslen(wcsPath); + wcscpy(aPath, pPath); + nPathLen = wcslen(aPath); } else return sal_False; @@ -1073,28 +1074,28 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, osl_freeSecurityHandle(security); if (bFailed) return (sal_False); - if (strConfigDir->length >= MAX_LONG_PATH) + if ( ::sal::static_int_cast< sal_uInt32 >( strConfigDir->length ) >= aPath.getBufSizeInSymbols() ) return sal_False; - wcscpy(wcsPath, strConfigDir->buffer); + wcscpy(aPath, strConfigDir->buffer); nPathLen = strConfigDir->length; } - if (nPathLen && (wcsPath[nPathLen - 1] != L'/') && (wcsPath[nPathLen - 1] != L'\\')) + if (nPathLen && (aPath[nPathLen - 1] != L'/') && (aPath[nPathLen - 1] != L'\\')) { - wcsPath[nPathLen++] = L'\\'; - wcsPath[nPathLen] = 0; + aPath[nPathLen++] = L'\\'; + aPath[nPathLen] = 0; } - if (nPathLen + nFileLen >= MAX_LONG_PATH) + if (nPathLen + nFileLen >= aPath.getBufSizeInSymbols()) return sal_False; /* append file name */ - wcscpy(wcsPath + nPathLen, wcsFile); + wcscpy(aPath + nPathLen, aFile); nPathLen += nFileLen; /* copy filename */ - rtl_uString_newFromStr_WithLength(&strTmp, wcsPath, nPathLen); + rtl_uString_newFromStr_WithLength(&strTmp, aPath, nPathLen); nError = osl_getFileURLFromSystemPath(strTmp, strProfileName); rtl_uString_release(strTmp); @@ -1142,10 +1143,10 @@ sal_uInt32 SAL_CALL osl_getProfileSections(oslProfile Profile, sal_Char* pszBuff } else { - CHAR szFileName[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_LONG_PATH, NULL, NULL); - n = GetPrivateProfileSectionNames(pszBuffer, MaxLen, szFileName); + WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, aFileName, aFileName.getBufSizeInSymbols(), NULL, NULL); + n = GetPrivateProfileSectionNames(pszBuffer, MaxLen, aFileName); } releaseProfile(pProfile); @@ -1156,35 +1157,6 @@ sal_uInt32 SAL_CALL osl_getProfileSections(oslProfile Profile, sal_Char* pszBuff - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*****************************************************************************/ /* Static Module Functions */ /*****************************************************************************/ @@ -1289,7 +1261,7 @@ static sal_Bool lockFile(const osl_TFile* pFile, osl_TLockMode eMode) static osl_TFile* openFileImpl(rtl_uString * strFileName, oslProfileOption ProfileFlags ) { - osl_TFile* pFile = calloc(1, sizeof(osl_TFile)); + osl_TFile* pFile = reinterpret_cast< osl_TFile*>( calloc( 1, sizeof(osl_TFile) ) ); sal_Bool bWriteable = sal_False; /* if ( ProfileFlags & ( osl_Profile_WRITELOCK | osl_Profile_FLUSHWRITE | osl_Profile_READWRITE ) )*/ @@ -2228,7 +2200,7 @@ static osl_TProfileImpl* acquireProfile(oslProfile Profile, sal_Bool bWriteable) - if ((pProfile = osl_openProfile(NULL, PFlags)) != NULL ) + if ( ( pProfile = (osl_TProfileImpl*)osl_openProfile( NULL, PFlags ) ) != NULL ) { pProfile->m_Flags |= FLG_AUTOOPEN; } @@ -2335,7 +2307,8 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str sal_Char Buffer[4096] = ""; sal_Char Product[132] = ""; - WCHAR wcsPath[MAX_LONG_PATH] = L""; + ::osl::LongPathBuffer< sal_Unicode > aPath( MAX_LONG_PATH ); + aPath[0] = 0; DWORD dwPathLen = 0; if (*strPath == L'"') @@ -2369,7 +2342,7 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str rtl_uString * strSVFallback = NULL; rtl_uString * strSVLocation = NULL; rtl_uString * strSVName = NULL; - sal_Char Dir[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Char > aDir( MAX_LONG_PATH ); oslProfile hProfile; rtl_uString_newFromAscii(&strSVFallback, SVERSION_FALLBACK); @@ -2395,11 +2368,11 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str && (stricmp(Product, pChr) < 0)) { osl_readProfileString( - hProfile, SVERSION_SECTION, pChr, Dir, - sizeof(Dir), ""); + hProfile, SVERSION_SECTION, pChr, aDir, + aDir.getBufSizeInSymbols(), ""); /* check for existence of path */ - if (access(Dir, 0) >= 0) + if (access(aDir, 0) >= 0) strcpy(Product, pChr); } } @@ -2430,11 +2403,11 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str && (stricmp(Product, pChr) < 0)) { osl_readProfileString( - hProfile, SVERSION_SECTION, pChr, Dir, - sizeof(Dir), ""); + hProfile, SVERSION_SECTION, pChr, aDir, + aDir.getBufSizeInSymbols(), ""); /* check for existence of path */ - if (access(Dir, 0) >= 0) + if (access(aDir, 0) >= 0) strcpy(Product, pChr); } } @@ -2474,31 +2447,31 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str ((nEnd = rtl_ustr_indexOfChar(pCommandArg + nStart + 1, L']')) != -1)) { dwPathLen = nEnd; - wcsncpy(wcsPath, pCommandArg + nStart + 1, dwPathLen ); - wcsPath[dwPathLen] = 0; + wcsncpy(aPath, pCommandArg + nStart + 1, dwPathLen ); + aPath[dwPathLen] = 0; /* build full path */ - if ((wcsPath[dwPathLen - 1] != L'/') && (wcsPath[dwPathLen - 1] != L'\\')) + if ((aPath[dwPathLen - 1] != L'/') && (aPath[dwPathLen - 1] != L'\\')) { - wcscpy(wcsPath + dwPathLen++, L"/"); + wcscpy(aPath + dwPathLen++, L"/"); } if (*strPath) { - wcscpy(wcsPath + dwPathLen, strPath); + wcscpy(aPath + dwPathLen, strPath); dwPathLen += wcslen(strPath); } else { - CHAR szPath[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Char > aTmpPath( MAX_LONG_PATH ); int n; - if ((n = WideCharToMultiByte(CP_ACP,0, wcsPath, -1, szPath, MAX_LONG_PATH, NULL, NULL)) > 0) + if ((n = WideCharToMultiByte(CP_ACP,0, aPath, -1, aTmpPath, aTmpPath.getBufSizeInSymbols(), NULL, NULL)) > 0) { - strcpy(szPath + n, SVERSION_USER); - if (access(szPath, 0) >= 0) + strcpy(aTmpPath + n, SVERSION_USER); + if (access(aTmpPath, 0) >= 0) { - dwPathLen += MultiByteToWideChar( CP_ACP, 0, SVERSION_USER, -1, wcsPath + dwPathLen, MAX_LONG_PATH - dwPathLen ); + dwPathLen += MultiByteToWideChar( CP_ACP, 0, SVERSION_USER, -1, aPath + dwPathLen, aPath.getBufSizeInSymbols() - dwPathLen ); } } } @@ -2538,16 +2511,16 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str } else { - wcsncpy(wcsPath, strExecutable->buffer, nPos ); - wcsPath[nPos] = 0; + wcsncpy(aPath, strExecutable->buffer, nPos ); + aPath[nPos] = 0; dwPathLen = nPos; } } else { - wcsncpy(wcsPath, strExecutable->buffer, nPos ); + wcsncpy(aPath, strExecutable->buffer, nPos ); dwPathLen = nPos; - wcsPath[dwPathLen] = 0; + aPath[dwPathLen] = 0; } /* if we have no product identification use the executable file name */ @@ -2563,30 +2536,30 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str rtl_uString_release(strExecutable); /* remember last subdir */ - nPos = rtl_ustr_lastIndexOfChar(wcsPath, L'\\'); + nPos = rtl_ustr_lastIndexOfChar(aPath, L'\\'); - wcscpy(wcsPath + dwPathLen++, L"\\"); + wcscpy(aPath + dwPathLen++, L"\\"); if (*strPath) { - wcscpy(wcsPath + dwPathLen, strPath); + wcscpy(aPath + dwPathLen, strPath); dwPathLen += wcslen(strPath); } { - CHAR szPath[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Char > aTmpPath( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, wcsPath, -1, szPath, MAX_LONG_PATH, NULL, NULL); + WideCharToMultiByte(CP_ACP,0, aPath, -1, aTmpPath, aTmpPath.getBufSizeInSymbols(), NULL, NULL); /* if file not exists, remove any specified subdirectories like "bin" or "program" */ - if (((access(szPath, 0) < 0) && (nPos != -1)) || (*strPath == 0)) + if (((access(aTmpPath, 0) < 0) && (nPos != -1)) || (*strPath == 0)) { static sal_Char *SubDirs[] = SVERSION_DIRS; int i = 0; - pStr = szPath + nPos; + pStr = aTmpPath + nPos; for (i = 0; i < (sizeof(SubDirs) / sizeof(SubDirs[0])); i++) if (strnicmp(pStr + 1, SubDirs[i], strlen(SubDirs[i])) == 0) @@ -2594,18 +2567,18 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str if ( *strPath == 0) { strcpy(pStr + 1,SVERSION_USER); - if ( access(szPath, 0) < 0 ) + if ( access(aTmpPath, 0) < 0 ) { *(pStr+1)='\0'; } else { - dwPathLen = nPos + MultiByteToWideChar( CP_ACP, 0, SVERSION_USER, -1, wcsPath + nPos + 1, MAX_LONG_PATH - (nPos + 1) ); + dwPathLen = nPos + MultiByteToWideChar( CP_ACP, 0, SVERSION_USER, -1, aPath + nPos + 1, aPath.getBufSizeInSymbols() - (nPos + 1) ); } } else { - wcscpy(wcsPath + nPos + 1, strPath); + wcscpy(aPath + nPos + 1, strPath); dwPathLen = nPos + 1 + wcslen(strPath); } @@ -2614,20 +2587,20 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str } } - if ((wcsPath[dwPathLen - 1] != L'/') && (wcsPath[dwPathLen - 1] != L'\\')) + if ((aPath[dwPathLen - 1] != L'/') && (aPath[dwPathLen - 1] != L'\\')) { - wcsPath[dwPathLen++] = L'\\'; - wcsPath[dwPathLen] = 0; + aPath[dwPathLen++] = L'\\'; + aPath[dwPathLen] = 0; } - wcscpy(wcsPath + dwPathLen, strFile); + wcscpy(aPath + dwPathLen, strFile); { - CHAR szPath[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Char > aTmpPath( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, wcsPath, -1, szPath, MAX_LONG_PATH, NULL, NULL); + WideCharToMultiByte(CP_ACP,0, aPath, -1, aTmpPath, aTmpPath.getBufSizeInSymbols(), NULL, NULL); - if ((access(szPath, 0) < 0) && (strlen(Product) > 0)) + if ((access(aTmpPath, 0) < 0) && (strlen(Product) > 0)) { rtl_uString * strSVFallback = NULL; rtl_uString * strSVProfile = NULL; @@ -2676,38 +2649,38 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str if (strlen(Buffer) > 0) { dwPathLen = MultiByteToWideChar( - CP_ACP, 0, Buffer, -1, wcsPath, MAX_LONG_PATH ); + CP_ACP, 0, Buffer, -1, aPath, aPath.getBufSizeInSymbols() ); dwPathLen -=1; /* build full path */ - if ((wcsPath[dwPathLen - 1] != L'/') - && (wcsPath[dwPathLen - 1] != L'\\')) + if ((aPath[dwPathLen - 1] != L'/') + && (aPath[dwPathLen - 1] != L'\\')) { - wcscpy(wcsPath + dwPathLen++, L"\\"); + wcscpy(aPath + dwPathLen++, L"\\"); } if (*strPath) { - wcscpy(wcsPath + dwPathLen, strPath); + wcscpy(aPath + dwPathLen, strPath); dwPathLen += wcslen(strPath); } else { - CHAR szPath[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Char > aTmpPath( MAX_LONG_PATH ); int n; if ((n = WideCharToMultiByte( - CP_ACP,0, wcsPath, -1, szPath, - MAX_LONG_PATH, NULL, NULL)) + CP_ACP,0, aPath, -1, aTmpPath, + aTmpPath.getBufSizeInSymbols(), NULL, NULL)) > 0) { - strcpy(szPath + n, SVERSION_USER); - if (access(szPath, 0) >= 0) + strcpy(aTmpPath + n, SVERSION_USER); + if (access(aTmpPath, 0) >= 0) { dwPathLen += MultiByteToWideChar( CP_ACP, 0, SVERSION_USER, -1, - wcsPath + dwPathLen, - MAX_LONG_PATH - dwPathLen ); + aPath + dwPathLen, + aPath.getBufSizeInSymbols() - dwPathLen ); } } } @@ -2723,11 +2696,11 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str } } - wcsPath[dwPathLen] = 0; + aPath[dwPathLen] = 0; } /* copy filename */ - wcscpy(strProfile, wcsPath); + wcscpy(strProfile, aPath); return sal_True; } diff --git a/sal/osl/w32/signal.c b/sal/osl/w32/signal.cxx index d79f99f150d7..755ac86c7abf 100644 --- a/sal/osl/w32/signal.c +++ b/sal/osl/w32/signal.cxx @@ -33,6 +33,7 @@ #include <tchar.h> #include "file_url.h" +#include "path_helper.hxx" #include <osl/diagnose.h> #include <osl/mutex.h> @@ -117,7 +118,7 @@ static BOOL ReportCrash( LPEXCEPTION_POINTERS lpEP ) BOOL fSuccess = FALSE; BOOL fAutoReport = FALSE; TCHAR szBuffer[1024]; - TCHAR szPath[MAX_LONG_PATH]; + ::osl::LongPathBuffer< sal_Char > aPath( MAX_LONG_PATH ); LPTSTR lpFilePart; PROCESS_INFORMATION ProcessInfo; STARTUPINFO StartupInfo; @@ -169,11 +170,11 @@ static BOOL ReportCrash( LPEXCEPTION_POINTERS lpEP ) value_len = quote - value; } - lpVariable = _alloca( variable_len + 1 ); + lpVariable = reinterpret_cast< CHAR* >( _alloca( variable_len + 1 ) ); memcpy( lpVariable, variable, variable_len ); lpVariable[variable_len] = 0; - lpValue = _alloca( value_len + 1); + lpValue = reinterpret_cast< CHAR* >( _alloca( value_len + 1) ); memcpy( lpValue, value, value_len ); lpValue[value_len] = 0; @@ -182,7 +183,7 @@ static BOOL ReportCrash( LPEXCEPTION_POINTERS lpEP ) } } - if ( SearchPath( NULL, TEXT("crashrep.exe"), NULL, MAX_LONG_PATH, szPath, &lpFilePart ) ) + if ( SearchPath( NULL, TEXT( "crashrep.exe" ), NULL, aPath.getBufSizeInSymbols(), aPath, &lpFilePart ) ) { ZeroMemory( &StartupInfo, sizeof(StartupInfo) ); StartupInfo.cb = sizeof(StartupInfo.cb); @@ -190,7 +191,7 @@ static BOOL ReportCrash( LPEXCEPTION_POINTERS lpEP ) sntprintf( szBuffer, elementsof(szBuffer), _T("%s -p %u -excp 0x%p -t %u%s"), - szPath, + aPath, GetCurrentProcessId(), lpEP, GetCurrentThreadId(), @@ -319,6 +320,8 @@ static long WINAPI SignalHandlerFunction(LPEXCEPTION_POINTERS lpEP) SetErrorMode(SEM_NOGPFAULTERRORBOX); exit(255); break; + default: + break; } return (EXCEPTION_CONTINUE_EXECUTION); @@ -336,7 +339,7 @@ oslSignalHandler SAL_CALL osl_addSignalHandler(oslSignalHandlerFunction Handler, if (! bInitSignal) bInitSignal = InitSignal(); - pHandler = calloc(1, sizeof(oslSignalHandlerImpl)); + pHandler = reinterpret_cast< oslSignalHandlerImpl* >( calloc( 1, sizeof(oslSignalHandlerImpl) ) ); if (pHandler != NULL) { diff --git a/sal/osl/w32/tempfile.cxx b/sal/osl/w32/tempfile.cxx index d5ba27d3e28f..9b5cc4458caa 100644 --- a/sal/osl/w32/tempfile.cxx +++ b/sal/osl/w32/tempfile.cxx @@ -37,6 +37,7 @@ #include "file_error.h" #include "file_url.h" +#include "path_helper.hxx" #include "osl/diagnose.h" @@ -241,25 +242,21 @@ oslFileError SAL_CALL osl_createTempFile( //############################################# oslFileError SAL_CALL osl_getTempDirURL(rtl_uString** pustrTempDir) { - WCHAR szBuffer[MAX_LONG_PATH]; - LPWSTR lpBuffer = szBuffer; - DWORD nBufferLength = ELEMENTS_OF_ARRAY(szBuffer) - 1; + ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + LPWSTR lpBuffer = aBuffer; + DWORD nBufferLength = aBuffer.getBufSizeInSymbols() - 1; DWORD nLength; oslFileError error; - do + nLength = GetTempPathW( aBuffer.getBufSizeInSymbols(), lpBuffer ); + + if ( nLength > nBufferLength ) { - nLength = GetTempPathW( ELEMENTS_OF_ARRAY(szBuffer), lpBuffer ); - if ( nLength > nBufferLength ) - { - nLength++; - lpBuffer = reinterpret_cast<WCHAR*>(alloca( sizeof(WCHAR) * nLength )); - nBufferLength = nLength - 1; - } - } while ( nLength > nBufferLength ); - - if ( nLength ) + // the provided path has invalid length + error = osl_File_E_NOENT; + } + else if ( nLength ) { rtl_uString *ustrTempPath = NULL; @@ -277,3 +274,4 @@ oslFileError SAL_CALL osl_getTempDirURL(rtl_uString** pustrTempDir) return error; } + |