diff options
Diffstat (limited to 'sal')
-rw-r--r-- | sal/inc/osl/file.h | 8 | ||||
-rw-r--r-- | sal/osl/unx/file.cxx | 23 | ||||
-rw-r--r-- | sal/osl/w32/file_dirvol.cxx | 217 | ||||
-rw-r--r-- | sal/osl/w32/file_url.cxx | 325 | ||||
-rw-r--r-- | sal/osl/w32/file_url.h | 6 | ||||
-rw-r--r-- | sal/osl/w32/module.cxx (renamed from sal/osl/w32/module.c) | 20 | ||||
-rw-r--r-- | sal/osl/w32/path_helper.hxx | 40 | ||||
-rw-r--r-- | sal/osl/w32/process.cxx (renamed from sal/osl/w32/process.c) | 38 | ||||
-rw-r--r-- | sal/osl/w32/profile.cxx (renamed from sal/osl/w32/profile.c) | 247 | ||||
-rw-r--r-- | sal/osl/w32/signal.cxx (renamed from sal/osl/w32/signal.c) | 17 | ||||
-rw-r--r-- | sal/osl/w32/system.h | 12 | ||||
-rw-r--r-- | sal/osl/w32/tempfile.cxx | 28 | ||||
-rw-r--r-- | sal/rtl/source/ustring.c | 8 |
13 files changed, 647 insertions, 342 deletions
diff --git a/sal/inc/osl/file.h b/sal/inc/osl/file.h index 3e7a85dfe662..27ee5c9f12d8 100644 --- a/sal/inc/osl/file.h +++ b/sal/inc/osl/file.h @@ -814,6 +814,14 @@ oslFileError SAL_CALL osl_getFileSize( oslFileHandle Handle, sal_uInt64 *pSize ) */ #define osl_File_MapFlag_RandomAccess ((sal_uInt32)(0x1)) +/** Map flag denoting that the mapped address space will be accessed by the + process soon (and it is advantageous for the operating system to already + start paging in the data). + + @since UDK 3.2.12 + */ +#define osl_File_MapFlag_WillNeed ((sal_uInt32)(0x2)) + /** Map a shared file into memory. @since UDK 3.2.10 diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index e02485cdf4ce..43dcd0cf179c 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -1082,6 +1082,29 @@ SAL_CALL osl_mapFile ( } } } + if (uFlags & osl_File_MapFlag_WillNeed) + { + // On Linux, madvise(..., MADV_WILLNEED) appears to have the undesirable + // effect of not returning until the data has actually been paged in, so + // that its net effect would typically be to slow down the process + // (which could start processing at the beginning of the data while the + // OS simultaneously pages in the rest); on other platforms, it remains + // to be evaluated whether madvise or equivalent is available and + // actually useful: +#if defined MACOSX + int e = posix_madvise(p, nLength, POSIX_MADV_WILLNEED); + if (e != 0) + { + OSL_TRACE( + "posix_madvise(..., POSIX_MADV_WILLNEED) failed with %d", e); + } +#elif defined SOLARIS + if (madvise(static_cast< caddr_t >(p), nLength, MADV_WILLNEED) != 0) + { + OSL_TRACE("madvise(..., MADV_WILLNEED) failed with %d", errno); + } +#endif + } return osl_File_E_None; } diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx index 5ea839ae215d..dbab4864cb28 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" @@ -294,7 +295,7 @@ struct DirectoryItem_Impl WIN32_FIND_DATA FindData; TCHAR cDriveString[MAX_PATH]; }; - TCHAR szFullPath[MAX_PATH]; + rtl_uString* m_pFullPath; BOOL bFullPathNormalized; int nRefCount; }; @@ -313,7 +314,7 @@ struct Directory_Impl HANDLE hDirectory; HANDLE hEnumDrives; }; - TCHAR szDirectoryPath[MAX_PATH]; + rtl_uString* m_pDirectoryPath; }; //##################################################### @@ -398,34 +399,48 @@ typedef struct tagDIRECTORY } DIRECTORY, *PDIRECTORY, FAR *LPDIRECTORY; //##################################################### -static HANDLE WINAPI OpenDirectory(LPCTSTR lpszPath) +static HANDLE WINAPI OpenDirectory( rtl_uString* pPath) { - LPDIRECTORY pDirectory = (LPDIRECTORY)HeapAlloc(GetProcessHeap(), 0, sizeof(DIRECTORY)); + LPDIRECTORY pDirectory = NULL; - if (pDirectory) + if ( pPath ) { - TCHAR szFileMask[MAX_PATH]; - int nLen; + sal_uInt32 nLen = rtl_uString_getLength( pPath ); + if ( nLen ) + { + TCHAR* pSuffix = 0; + sal_uInt32 nSuffLen = 0; + + if ( pPath->buffer[nLen - 1] != L'\\' ) + { + pSuffix = L"\\*.*"; + nSuffLen = 4; + } + else + { + pSuffix = L"*.*"; + nSuffLen = 3; + } - _tcscpy( szFileMask, lpszPath ); - nLen = _tcslen( szFileMask ); + TCHAR* szFileMask = reinterpret_cast< TCHAR* >( rtl_allocateMemory( sizeof( TCHAR ) * ( nLen + nSuffLen + 1 ) ) ); - if (nLen && szFileMask[nLen-1] != '\\') - _tcscat(szFileMask, TEXT("\\*.*")); - else - _tcscat(szFileMask, TEXT("*.*")); + _tcscpy( szFileMask, reinterpret_cast<LPCTSTR>( rtl_uString_getStr( pPath ) ) ); + _tcscat( szFileMask, pSuffix ); - pDirectory->hFind = FindFirstFile(szFileMask, &pDirectory->aFirstData); + pDirectory = (LPDIRECTORY)HeapAlloc(GetProcessHeap(), 0, sizeof(DIRECTORY)); + pDirectory->hFind = FindFirstFile(szFileMask, &pDirectory->aFirstData); - if (!IsValidHandle(pDirectory->hFind)) - { - if ( GetLastError() != ERROR_NO_MORE_FILES ) + if (!IsValidHandle(pDirectory->hFind)) { - HeapFree(GetProcessHeap(), 0, pDirectory); - pDirectory = NULL; + if ( GetLastError() != ERROR_NO_MORE_FILES ) + { + HeapFree(GetProcessHeap(), 0, pDirectory); + pDirectory = NULL; + } } } } + return (HANDLE)pDirectory; } @@ -502,15 +517,26 @@ static oslFileError osl_openLocalRoot( Directory_Impl *pDirImpl; pDirImpl = reinterpret_cast<Directory_Impl*>(rtl_allocateMemory( sizeof(Directory_Impl))); - _tcscpy( pDirImpl->szDirectoryPath, reinterpret_cast<LPCTSTR>(rtl_uString_getStr(strSysPath)) ); + ZeroMemory( pDirImpl, sizeof(Directory_Impl) ); + rtl_uString_newFromString( &pDirImpl->m_pDirectoryPath, strSysPath ); /* Append backslash if neccessary */ /* @@@ToDo use function ensure backslash */ - if ( pDirImpl->szDirectoryPath[_tcslen(pDirImpl->szDirectoryPath) - 1] != L'\\' ) - _tcscat( pDirImpl->szDirectoryPath, L"\\" ); + sal_uInt32 nLen = rtl_uString_getLength( pDirImpl->m_pDirectoryPath ); + if ( nLen && pDirImpl->m_pDirectoryPath->buffer[nLen - 1] != L'\\' ) + { + rtl_uString* pCurDir = 0; + rtl_uString* pBackSlash = 0; + + rtl_uString_assign( &pCurDir, pDirImpl->m_pDirectoryPath ); + rtl_uString_newFromStr( &pBackSlash, L"\\" ); + rtl_uString_newConcat( &pDirImpl->m_pDirectoryPath, pCurDir, pBackSlash ); + rtl_uString_release( pBackSlash ); + rtl_uString_release( pCurDir ); + } pDirImpl->uType = DIRECTORYTYPE_LOCALROOT; pDirImpl->hEnumDrives = OpenLogicalDrivesEnum(); @@ -526,7 +552,16 @@ static oslFileError osl_openLocalRoot( else { if ( pDirImpl ) + { + if ( pDirImpl->m_pDirectoryPath ) + { + rtl_uString_release( pDirImpl->m_pDirectoryPath ); + pDirImpl->m_pDirectoryPath = 0; + } + rtl_freeMemory(pDirImpl); + pDirImpl = 0; + } error = oslTranslateFileError( GetLastError() ); } @@ -547,23 +582,41 @@ static oslFileError SAL_CALL osl_openFileDirectory( *pDirectory = NULL; Directory_Impl *pDirImpl = reinterpret_cast<Directory_Impl*>(rtl_allocateMemory(sizeof(Directory_Impl))); - _tcscpy( pDirImpl->szDirectoryPath, reinterpret_cast<LPCTSTR>(rtl_uString_getStr(strDirectoryPath)) ); + ZeroMemory( pDirImpl, sizeof(Directory_Impl) ); + rtl_uString_newFromString( &pDirImpl->m_pDirectoryPath, strDirectoryPath ); /* Append backslash if neccessary */ /* @@@ToDo use function ensure backslash */ - if ( pDirImpl->szDirectoryPath[_tcslen(pDirImpl->szDirectoryPath) - 1] != L'\\' ) - _tcscat( pDirImpl->szDirectoryPath, L"\\" ); + sal_uInt32 nLen = rtl_uString_getLength( pDirImpl->m_pDirectoryPath ); + if ( nLen && pDirImpl->m_pDirectoryPath->buffer[nLen - 1] != L'\\' ) + { + rtl_uString* pCurDir = 0; + rtl_uString* pBackSlash = 0; + + rtl_uString_assign( &pCurDir, pDirImpl->m_pDirectoryPath ); + rtl_uString_newFromStr( &pBackSlash, L"\\" ); + rtl_uString_newConcat( &pDirImpl->m_pDirectoryPath, pCurDir, pBackSlash ); + rtl_uString_release( pBackSlash ); + rtl_uString_release( pCurDir ); + } + pDirImpl->uType = DIRECTORYTYPE_FILESYSTEM; - pDirImpl->hDirectory = OpenDirectory( pDirImpl->szDirectoryPath ); + pDirImpl->hDirectory = OpenDirectory( pDirImpl->m_pDirectoryPath ); if ( !pDirImpl->hDirectory ) { error = oslTranslateFileError( GetLastError() ); + if ( pDirImpl->m_pDirectoryPath ) + { + rtl_uString_release( pDirImpl->m_pDirectoryPath ); + pDirImpl->m_pDirectoryPath = 0; + } + rtl_freeMemory(pDirImpl), pDirImpl = 0; } @@ -595,6 +648,7 @@ static oslFileError SAL_CALL osl_openNetworkServer( Directory_Impl *pDirImpl; pDirImpl = reinterpret_cast<Directory_Impl*>(rtl_allocateMemory(sizeof(Directory_Impl))); + ZeroMemory( pDirImpl, sizeof(Directory_Impl) ); pDirImpl->uType = DIRECTORYTYPE_NETROOT; pDirImpl->hDirectory = hEnum; *pDirectory = (oslDirectory)pDirImpl; @@ -612,7 +666,11 @@ static DWORD create_dir_with_callback( // user specified callback function. On success // the function returns ERROR_SUCCESS else a Win32 error code. - if (CreateDirectory(reinterpret_cast<LPCTSTR>(dir_path->buffer), NULL)) + BOOL bCreated = FALSE; + + bCreated = CreateDirectoryW( reinterpret_cast<LPCWSTR>(rtl_uString_getStr( dir_path )), NULL ); + + if ( bCreated ) { if (aDirectoryCreationCallbackFunc) { @@ -708,15 +766,18 @@ oslFileError SAL_CALL osl_createDirectory(rtl_uString* strPath) if ( osl_File_E_None == error ) { - if ( CreateDirectoryW( reinterpret_cast<LPCWSTR>(rtl_uString_getStr( strSysPath )), NULL ) ) - error = osl_File_E_None; -/*@@@ToDo - The else case is a hack because the ucb or the webtop had some - problems with the error code that CreateDirectory returns in - case the path is only a logical drive, should be removed! -*/ - else + BOOL bCreated = FALSE; + + bCreated = CreateDirectoryW( reinterpret_cast<LPCWSTR>(rtl_uString_getStr( strSysPath )), NULL ); + + if ( !bCreated ) { + /*@@@ToDo + The following case is a hack because the ucb or the webtop had some + problems with the error code that CreateDirectory returns in + case the path is only a logical drive, should be removed! + */ + const sal_Unicode *pBuffer = rtl_uString_getStr( strSysPath ); sal_Int32 nLen = rtl_uString_getLength( strSysPath ); @@ -865,6 +926,12 @@ static oslFileError SAL_CALL osl_getNextDrive( } else { + if ( pItemImpl->m_pFullPath ) + { + rtl_uString_release( pItemImpl->m_pFullPath ); + pItemImpl->m_pFullPath = 0; + } + rtl_freeMemory( pItemImpl ); return oslTranslateFileError( GetLastError() ); } @@ -898,14 +965,24 @@ static oslFileError SAL_CALL osl_getNextFileItem( { pItemImpl->uType = DIRECTORYITEM_FILE; pItemImpl->nRefCount = 1; - _tcscpy( pItemImpl->szFullPath, pDirImpl->szDirectoryPath ); - _tcscat( pItemImpl->szFullPath, pItemImpl->FindData.cFileName ); + + rtl_uString* pTmpFileName = 0; + rtl_uString_newFromStr( &pTmpFileName, pItemImpl->FindData.cFileName ); + rtl_uString_newConcat( &pItemImpl->m_pFullPath, pDirImpl->m_pDirectoryPath, pTmpFileName ); + rtl_uString_release( pTmpFileName ); + pItemImpl->bFullPathNormalized = FALSE; *pItem = (oslDirectoryItem)pItemImpl; return osl_File_E_None; } else { + if ( pItemImpl->m_pFullPath ) + { + rtl_uString_release( pItemImpl->m_pFullPath ); + pItemImpl->m_pFullPath = 0; + } + rtl_freeMemory( pItemImpl ); return oslTranslateFileError( GetLastError() ); } @@ -966,6 +1043,12 @@ oslFileError SAL_CALL osl_closeDirectory(oslDirectory Directory) break; } + if ( pDirImpl->m_pDirectoryPath ) + { + rtl_uString_release( pDirImpl->m_pDirectoryPath ); + pDirImpl->m_pDirectoryPath = 0; + } + rtl_freeMemory(pDirImpl); } return eError; @@ -1027,8 +1110,7 @@ oslFileError SAL_CALL osl_getDirectoryItem(rtl_uString *strFilePath, oslDirector pItemImpl->uType = DIRECTORYITEM_SERVER; osl_acquireDirectoryItem( (oslDirectoryItem)pItemImpl ); - - _tcscpy( pItemImpl->szFullPath, reinterpret_cast<LPCTSTR>(strSysFilePath->buffer) ); + rtl_uString_newFromString( &pItemImpl->m_pFullPath, strSysFilePath ); // Assign a title anyway { @@ -1091,7 +1173,7 @@ oslFileError SAL_CALL osl_getDirectoryItem(rtl_uString *strFilePath, oslDirector osl_acquireDirectoryItem( (oslDirectoryItem)pItemImpl ); CopyMemory( &pItemImpl->FindData, &aFindData, sizeof(WIN32_FIND_DATA) ); - _tcscpy( pItemImpl->szFullPath, reinterpret_cast<LPCTSTR>(rtl_uString_getStr(strSysFilePath)) ); + rtl_uString_newFromString( &pItemImpl->m_pFullPath, strSysFilePath ); // MT: This costs 600ms startup time on fast v60x! // GetCaseCorrectPathName( pItemImpl->szFullPath, pItemImpl->szFullPath, sizeof(pItemImpl->szFullPath) ); @@ -1133,7 +1215,16 @@ oslFileError SAL_CALL osl_releaseDirectoryItem( oslDirectoryItem Item ) return osl_File_E_INVAL; if ( ! --pItemImpl->nRefCount ) + { + if ( pItemImpl->m_pFullPath ) + { + rtl_uString_release( pItemImpl->m_pFullPath ); + pItemImpl->m_pFullPath = 0; + } + rtl_freeMemory( pItemImpl ); + } + return osl_File_E_None; } @@ -1347,18 +1438,22 @@ static oslFileError get_filesystem_attributes( } if (is_filesystem_attributes_request(field_mask)) { - WCHAR vn[MAX_PATH]; - WCHAR fsn[MAX_PATH]; + /* the following two parameters can not be longer than MAX_PATH+1 */ + WCHAR vn[MAX_PATH+1]; + WCHAR fsn[MAX_PATH+1]; + DWORD serial; DWORD mcl; DWORD flags; LPCTSTR pszPath = reinterpret_cast<LPCTSTR>(path.getStr()); - if (GetVolumeInformation(pszPath, vn, MAX_PATH, &serial, &mcl, &flags, fsn, MAX_PATH)) + if (GetVolumeInformation(pszPath, vn, MAX_PATH+1, &serial, &mcl, &flags, fsn, MAX_PATH+1)) { + // Currently sal does not use this value, instead MAX_PATH is used pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxNameLength; pInfo->uMaxNameLength = mcl; + // Should the uMaxPathLength be set to 32767, "\\?\" prefix allowes it pInfo->uValidFields |= osl_VolumeInfo_Mask_MaxPathLength; pInfo->uMaxPathLength = MAX_PATH; @@ -1561,11 +1656,7 @@ static oslFileError SAL_CALL osl_getServerInfo( if ( uFieldMask & osl_FileStatus_Mask_FileURL ) { - rtl_uString *ustrSystemPath = NULL; - - rtl_uString_newFromStr( &ustrSystemPath, reinterpret_cast<const sal_Unicode*>(pItemImpl->szFullPath) ); - osl_getFileURLFromSystemPath( ustrSystemPath, &pStatus->ustrFileURL ); - rtl_uString_release( ustrSystemPath ); + osl_getFileURLFromSystemPath( pItemImpl->m_pFullPath, &pStatus->ustrFileURL ); pStatus->uValidFields |= osl_FileStatus_Mask_FileURL; } return osl_File_E_None; @@ -1594,7 +1685,7 @@ oslFileError SAL_CALL osl_getFileStatus( if ( uFieldMask & osl_FileStatus_Mask_Validate ) { - HANDLE hFind = FindFirstFile( pItemImpl->szFullPath, &pItemImpl->FindData ); + HANDLE hFind = FindFirstFile( reinterpret_cast<LPCTSTR>( rtl_uString_getStr( pItemImpl->m_pFullPath ) ), &pItemImpl->FindData ); if ( hFind != INVALID_HANDLE_VALUE ) FindClose( hFind ); @@ -1654,28 +1745,30 @@ oslFileError SAL_CALL osl_getFileStatus( if ( uFieldMask & osl_FileStatus_Mask_LinkTargetURL ) { - rtl_uString *ustrFullPath = NULL; - - rtl_uString_newFromStr( &ustrFullPath, reinterpret_cast<const sal_Unicode*>(pItemImpl->szFullPath) ); - osl_getFileURLFromSystemPath( ustrFullPath, &pStatus->ustrLinkTargetURL ); - rtl_uString_release( ustrFullPath ); + osl_getFileURLFromSystemPath( pItemImpl->m_pFullPath, &pStatus->ustrLinkTargetURL ); pStatus->uValidFields |= osl_FileStatus_Mask_LinkTargetURL; } if ( uFieldMask & osl_FileStatus_Mask_FileURL ) { - rtl_uString *ustrFullPath = NULL; - - if ( !pItemImpl->bFullPathNormalized ) { - GetCaseCorrectPathName( pItemImpl->szFullPath, pItemImpl->szFullPath, sizeof(pItemImpl->szFullPath) ); - pItemImpl->bFullPathNormalized = TRUE; + sal_uInt32 nLen = rtl_uString_getLength( pItemImpl->m_pFullPath ); + ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + sal_uInt32 nNewLen = GetCaseCorrectPathName( reinterpret_cast<LPCTSTR>( rtl_uString_getStr( pItemImpl->m_pFullPath ) ), + aBuffer, + aBuffer.getBufSizeInSymbols(), + sal_True ); + + if ( nNewLen ) + { + rtl_uString_newFromStr( &pItemImpl->m_pFullPath, aBuffer ); + pItemImpl->bFullPathNormalized = TRUE; + } } - rtl_uString_newFromStr( &ustrFullPath, reinterpret_cast<const sal_Unicode*>(pItemImpl->szFullPath) ); - osl_getFileURLFromSystemPath( ustrFullPath, &pStatus->ustrFileURL ); - rtl_uString_release( ustrFullPath ); + + osl_getFileURLFromSystemPath( pItemImpl->m_pFullPath, &pStatus->ustrFileURL ); pStatus->uValidFields |= osl_FileStatus_Mask_FileURL; } diff --git a/sal/osl/w32/file_url.cxx b/sal/osl/w32/file_url.cxx index 968c4bccc95e..45f8c726a93e 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> @@ -52,6 +54,11 @@ #define ELEMENTS_OF_ARRAY(arr) (sizeof(arr)/(sizeof((arr)[0]))) +#define WSTR_SYSTEM_ROOT_PATH L"\\\\.\\" +#define WSTR_LONG_PATH_PREFIX L"\\\\?\\" +#define WSTR_LONG_PATH_PREFIX_UNC L"\\\\?\\UNC\\" + + //################################################################## // FileURL functions //################################################################## @@ -68,7 +75,7 @@ static BOOL IsValidFilePathComponent( BOOL fValid = TRUE; /* Assume success */ TCHAR cLast = 0; - /* Path component length must not exceed MAX_PATH */ + /* Path component length must not exceed MAX_PATH even if long path with "\\?\" prefix is used */ while ( !lpComponentEnd && lpCurrent && lpCurrent - lpComponent < MAX_PATH ) { @@ -235,31 +242,56 @@ static BOOL IsValidFilePathComponent( DWORD IsValidFilePath(rtl_uString *path, LPCTSTR *lppError, DWORD dwFlags, rtl_uString **corrected) { LPCTSTR lpszPath = reinterpret_cast< LPCTSTR >(path->buffer); - LPCTSTR lpComponent; + LPCTSTR lpComponent = lpszPath; BOOL fValid = TRUE; DWORD dwPathType = PATHTYPE_ERROR; + sal_Int32 nLength = rtl_uString_getLength( path ); if ( dwFlags & VALIDATEPATH_ALLOW_RELATIVE ) dwFlags |= VALIDATEPATH_ALLOW_ELLIPSE; if ( !lpszPath ) - { fValid = FALSE; - lpComponent = lpszPath; - } - /* Test for UNC path notation */ - if ( 2 == _tcsspn( lpszPath, CHARSET_SEPARATOR ) ) + DWORD dwCandidatPathType = PATHTYPE_ERROR; + + if ( 0 == rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( path->buffer, nLength, WSTR_LONG_PATH_PREFIX_UNC, ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX_UNC) - 1, ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX_UNC) - 1 ) ) + { + /* This is long path in UNC notation */ + lpComponent = lpszPath + ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX_UNC) - 1; + dwCandidatPathType = PATHTYPE_ABSOLUTE_UNC | PATHTYPE_IS_LONGPATH; + } + else if ( 0 == rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( path->buffer, nLength, WSTR_LONG_PATH_PREFIX, ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX) - 1, ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX) - 1 ) ) { - /* Place the pointer behind the leading to backslashes */ + /* This is long path */ + lpComponent = lpszPath + ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX) - 1; + if ( _istalpha( lpComponent[0] ) && ':' == lpComponent[1] ) + { + lpComponent += 2; + dwCandidatPathType = PATHTYPE_ABSOLUTE_LOCAL | PATHTYPE_IS_LONGPATH; + } + } + else if ( 2 == _tcsspn( lpszPath, CHARSET_SEPARATOR ) ) + { + /* The UNC path notation */ lpComponent = lpszPath + 2; + dwCandidatPathType = PATHTYPE_ABSOLUTE_UNC; + } + else if ( _istalpha( lpszPath[0] ) && ':' == lpszPath[1] ) + { + /* Local path verification. Must start with <drive>: */ + lpComponent = lpszPath + 2; + dwCandidatPathType = PATHTYPE_ABSOLUTE_LOCAL; + } + if ( ( dwCandidatPathType & PATHTYPE_MASK_TYPE ) == PATHTYPE_ABSOLUTE_UNC ) + { fValid = IsValidFilePathComponent( lpComponent, &lpComponent, VALIDATEPATH_ALLOW_ELLIPSE ); /* So far we have a valid servername. Now let's see if we also have a network resource */ - dwPathType = PATHTYPE_ABSOLUTE_UNC; + dwPathType = dwCandidatPathType; if ( fValid ) { @@ -294,20 +326,14 @@ DWORD IsValidFilePath(rtl_uString *path, LPCTSTR *lppError, DWORD dwFlags, rtl_u } } } - - /* Local path verification. Must start with <drive>: */ - else if ( _istalpha( lpszPath[0] ) && ':' == lpszPath[1] ) + else if ( ( dwCandidatPathType & PATHTYPE_MASK_TYPE ) == PATHTYPE_ABSOLUTE_LOCAL ) { - /* Place pointer behind correct drive specification */ - - lpComponent = lpszPath + 2; - if ( 1 == _tcsspn( lpComponent, CHARSET_SEPARATOR ) ) lpComponent++; else if ( *lpComponent ) fValid = FALSE; - dwPathType = PATHTYPE_ABSOLUTE_LOCAL; + dwPathType = dwCandidatPathType; /* Now we are behind the backslash or it was a simple drive without backslash */ @@ -317,10 +343,9 @@ DWORD IsValidFilePath(rtl_uString *path, LPCTSTR *lppError, DWORD dwFlags, rtl_u dwPathType |= PATHTYPE_IS_VOLUME; } } - - /* Can be a relative path */ else if ( dwFlags & VALIDATEPATH_ALLOW_RELATIVE ) { + /* Can be a relative path */ lpComponent = lpszPath; /* Relative path can start with a backslash */ @@ -334,10 +359,9 @@ DWORD IsValidFilePath(rtl_uString *path, LPCTSTR *lppError, DWORD dwFlags, rtl_u dwPathType = PATHTYPE_RELATIVE; } - - /* Anything else is an error */ else { + /* Anything else is an error */ fValid = FALSE; lpComponent = lpszPath; } @@ -367,7 +391,8 @@ DWORD IsValidFilePath(rtl_uString *path, LPCTSTR *lppError, DWORD dwFlags, rtl_u } } - if ( fValid && _tcslen( lpszPath ) >= MAX_PATH ) + /* The path can be longer than MAX_PATH only in case it has the longpath prefix */ + if ( fValid && !( dwPathType & PATHTYPE_IS_LONGPATH ) && _tcslen( lpszPath ) >= MAX_PATH ) { fValid = FALSE; lpComponent = lpszPath + MAX_PATH; @@ -379,38 +404,45 @@ DWORD IsValidFilePath(rtl_uString *path, LPCTSTR *lppError, DWORD dwFlags, rtl_u return fValid ? dwPathType : PATHTYPE_ERROR; } -//############################################# //##################################################### -//Undocumented in SHELL32.DLL ordinal 35 -static BOOL PathRemoveFileSpec(LPTSTR lpPath) +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; - fSuccess = TRUE; + if ( lpLastDelimiter > lpPath && *(lpLastDelimiter - 1) != ':' ) + { + *lpLastDelimiter = 0; + *lpFileName = 0; + nRemoved = nDelLen; + } } - } - else - { - *(++lpLastDelimiter) = 0; - fSuccess = TRUE; - } + else if ( nDelLen && nDelLen - 1 < nFileBufLen ) + { + _tcscpy( lpFileName, lpLastDelimiter + 1 ); + *(++lpLastDelimiter) = 0; + nRemoved = nDelLen - 1; + } + } } - return fSuccess; + + return nRemoved; } //##################################################### // Undocumented in SHELL32.DLL ordinal 32 -static LPTSTR PathAddBackslash(LPTSTR lpPath) +static LPTSTR PathAddBackslash(LPTSTR lpPath, sal_Int32 nBufLen) { LPTSTR lpEndPath = NULL; @@ -418,7 +450,7 @@ static LPTSTR PathAddBackslash(LPTSTR lpPath) { int nLen = _tcslen(lpPath); - if ( !nLen || lpPath[nLen-1] != '\\' && lpPath[nLen-1] != '/' && nLen < MAX_PATH - 1 ) + if ( !nLen || lpPath[nLen-1] != '\\' && lpPath[nLen-1] != '/' && nLen < nBufLen - 1 ) { lpEndPath = lpPath + nLen; *lpEndPath++ = '\\'; @@ -431,37 +463,31 @@ static LPTSTR PathAddBackslash(LPTSTR lpPath) //##################################################### // 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 -) + DWORD nSkipLevels, + BOOL bCheckExistence ) { - TCHAR szPath[MAX_PATH]; - BOOL fSuccess; - - cchBuffer = cchBuffer; /* avoid warnings */ - - _tcscpy( szPath, lpszShortPath ); - - fSuccess = PathRemoveFileSpec( szPath ); + ::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; } @@ -473,24 +499,36 @@ static DWORD GetCaseCorrectPathNameEx( else bSkipThis = FALSE; - GetCaseCorrectPathNameEx( szPath, szPath, MAX_PATH, nSkipLevels ); + GetCaseCorrectPathNameEx( lpszPath, cchBuffer, nSkipLevels, bCheckExistence ); - PathAddBackslash( szPath ); + PathAddBackslash( lpszPath, cchBuffer ); /* Analyze parent if not only a trailing backslash was cutted but a real file spec */ if ( !bSkipThis ) { - WIN32_FIND_DATA aFindFileData; - HANDLE hFind = FindFirstFile( lpszShortPath, &aFindFileData ); - - if ( IsValidHandle(hFind) ) + if ( bCheckExistence ) { - _tcscat( szPath, aFindFileData.cFileName[0] ? aFindFileData.cFileName : aFindFileData.cAlternateFileName ); + ::osl::LongPathBuffer< sal_Unicode > aShortPath( MAX_LONG_PATH ); + _tcscpy( aShortPath, lpszPath ); + _tcscat( aShortPath, szFile ); - FindClose( hFind ); + WIN32_FIND_DATA aFindFileData; + HANDLE hFind = FindFirstFile( aShortPath, &aFindFileData ); + + if ( IsValidHandle(hFind) ) + { + _tcscat( lpszPath, aFindFileData.cFileName[0] ? aFindFileData.cFileName : aFindFileData.cAlternateFileName ); + + FindClose( hFind ); + } + else + lpszPath[0] = 0; } else - return 0; + { + /* add the segment name back */ + _tcscat( lpszPath, szFile ); + } } } else @@ -499,14 +537,12 @@ 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 ); - - return _tcslen( lpszLongPath ); + return _tcslen( lpszPath ); } //##################################################### @@ -515,7 +551,8 @@ static DWORD GetCaseCorrectPathNameEx( DWORD GetCaseCorrectPathName( LPCTSTR lpszShortPath, // file name LPTSTR lpszLongPath, // path buffer - DWORD cchBuffer // size of path buffer + DWORD cchBuffer, // size of path buffer + BOOL bCheckExistence ) { /* Special handling for "\\.\" as system root */ @@ -531,12 +568,19 @@ DWORD GetCaseCorrectPathName( return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1; } } - else + else if ( lpszShortPath ) { - return GetCaseCorrectPathNameEx( lpszShortPath, lpszLongPath, cchBuffer, 0 ); + if ( _tcslen( lpszShortPath ) <= cchBuffer ) + { + _tcscpy( lpszLongPath, lpszShortPath ); + return GetCaseCorrectPathNameEx( lpszLongPath, cchBuffer, 0, bCheckExistence ); + } } + + return 0; } + //############################################# static sal_Bool _osl_decodeURL( rtl_String* strUTF8, rtl_uString** pstrDecodedURL ) { @@ -670,7 +714,6 @@ static void _osl_encodeURL( rtl_uString *strURL, rtl_String **pstrEncodedURL ) } //############################################# -#define WSTR_SYSTEM_ROOT_PATH L"\\\\.\\" oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **pustrPath, sal_Bool bAllowRelative ) { @@ -728,13 +771,60 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p if ( nDecodedLen == nSkip ) rtl_uString_newFromStr_WithLength( &strTempPath, reinterpret_cast<const sal_Unicode*>(WSTR_SYSTEM_ROOT_PATH), ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1 ); else - rtl_uString_newFromStr_WithLength( &strTempPath, pDecodedURL + nSkip, nDecodedLen - nSkip ); + { + /* do not separate the directory and file case, so the maximal path lengs without prefix is MAX_PATH-12 */ + if ( nDecodedLen - nSkip <= MAX_PATH - 12 ) + { + rtl_uString_newFromStr_WithLength( &strTempPath, pDecodedURL + nSkip, nDecodedLen - nSkip ); + } + else + { + ::osl::LongPathBuffer< sal_Unicode > aBuf( MAX_LONG_PATH ); + sal_uInt32 nNewLen = GetCaseCorrectPathName( pDecodedURL + nSkip, + aBuf, + aBuf.getBufSizeInSymbols(), + sal_False ); + + if ( nNewLen <= MAX_PATH - 12 + || 0 == rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL + nSkip, nDecodedLen - nSkip, WSTR_SYSTEM_ROOT_PATH, ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1, ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1 ) + || 0 == rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL + nSkip, nDecodedLen - nSkip, WSTR_LONG_PATH_PREFIX, ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX) - 1, ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX) - 1 ) ) + { + rtl_uString_newFromStr_WithLength( &strTempPath, aBuf, nNewLen ); + } + else if ( pDecodedURL[nSkip] == (sal_Unicode)'\\' && pDecodedURL[nSkip+1] == (sal_Unicode)'\\' ) + { + /* it should be an UNC path, use the according prefix */ + rtl_uString *strSuffix = NULL; + rtl_uString *strPrefix = NULL; + rtl_uString_newFromStr_WithLength( &strPrefix, WSTR_LONG_PATH_PREFIX_UNC, ELEMENTS_OF_ARRAY( WSTR_LONG_PATH_PREFIX_UNC ) - 1 ); + rtl_uString_newFromStr_WithLength( &strSuffix, aBuf + 2, nNewLen - 2 ); + + rtl_uString_newConcat( &strTempPath, strPrefix, strSuffix ); + + rtl_uString_release( strPrefix ); + rtl_uString_release( strSuffix ); + } + else + { + rtl_uString *strSuffix = NULL; + rtl_uString *strPrefix = NULL; + rtl_uString_newFromStr_WithLength( &strPrefix, WSTR_LONG_PATH_PREFIX, ELEMENTS_OF_ARRAY( WSTR_LONG_PATH_PREFIX ) - 1 ); + rtl_uString_newFromStr_WithLength( &strSuffix, aBuf, nNewLen ); + + rtl_uString_newConcat( &strTempPath, strPrefix, strSuffix ); + + rtl_uString_release( strPrefix ); + rtl_uString_release( strSuffix ); + } + } + } if ( IsValidFilePath( strTempPath, NULL, VALIDATEPATH_ALLOW_ELLIPSE, &strTempPath ) ) nError = osl_File_E_None; } else if ( bAllowRelative ) /* This maybe a relative file URL */ { + /* In future the relative path could be converted to absolute if it is too long */ rtl_uString_assign( &strTempPath, strDecodedURL ); if ( IsValidFilePath( strTempPath, NULL, VALIDATEPATH_ALLOW_RELATIVE | VALIDATEPATH_ALLOW_ELLIPSE, &strTempPath ) ) @@ -777,8 +867,51 @@ oslFileError _osl_getFileURLFromSystemPath( rtl_uString* strPath, rtl_uString** { rtl_uString *strTempPath = NULL; - /* Replace backslashes */ - rtl_uString_newReplace( &strTempPath, strPath, '\\', '/' ); + if ( dwPathType & PATHTYPE_IS_LONGPATH ) + { + rtl_uString *strBuffer = NULL; + sal_uInt32 nIgnore = 0; + sal_uInt32 nLength = 0; + + /* the path has the longpath prefix, lets remove it */ + switch ( dwPathType & PATHTYPE_MASK_TYPE ) + { + case PATHTYPE_ABSOLUTE_UNC: + nIgnore = ELEMENTS_OF_ARRAY( WSTR_LONG_PATH_PREFIX_UNC ) - 1; + OSL_ENSURE( nIgnore == 8, "Unexpected long path UNC prefix!" ); + + /* generate the normal UNC path */ + nLength = rtl_uString_getLength( strPath ); + rtl_uString_newFromStr_WithLength( &strBuffer, strPath->buffer + nIgnore - 2, nLength - nIgnore + 2 ); + strBuffer->buffer[0] = '\\'; + + rtl_uString_newReplace( &strTempPath, strBuffer, '\\', '/' ); + rtl_uString_release( strBuffer ); + break; + + case PATHTYPE_ABSOLUTE_LOCAL: + nIgnore = ELEMENTS_OF_ARRAY( WSTR_LONG_PATH_PREFIX ) - 1; + OSL_ENSURE( nIgnore == 4, "Unexpected long path prefix!" ); + + /* generate the normal path */ + nLength = rtl_uString_getLength( strPath ); + rtl_uString_newFromStr_WithLength( &strBuffer, strPath->buffer + nIgnore, nLength - nIgnore ); + + rtl_uString_newReplace( &strTempPath, strBuffer, '\\', '/' ); + rtl_uString_release( strBuffer ); + break; + + default: + OSL_ASSERT( "Unexpected long path format!" ); + rtl_uString_newReplace( &strTempPath, strPath, '\\', '/' ); + break; + } + } + else + { + /* Replace backslashes */ + rtl_uString_newReplace( &strTempPath, strPath, '\\', '/' ); + } switch ( dwPathType & PATHTYPE_MASK_TYPE ) { @@ -947,8 +1080,8 @@ oslFileError SAL_CALL osl_getAbsoluteFileURL( rtl_uString* ustrBaseURL, rtl_uStr if ( !eError ) { - TCHAR szBuffer[MAX_PATH]; - TCHAR szCurrentDir[MAX_PATH]; + ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + ::osl::LongPathBuffer< sal_Unicode > aCurrentDir( MAX_LONG_PATH ); LPTSTR lpFilePart = NULL; DWORD dwResult; @@ -963,28 +1096,28 @@ oslFileError SAL_CALL osl_getAbsoluteFileURL( rtl_uString* ustrBaseURL, rtl_uStr { osl_acquireMutex( g_CurrentDirectoryMutex ); - GetCurrentDirectory( MAX_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_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_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/file_url.h b/sal/osl/w32/file_url.h index af23203fa0a7..2b2c79a41eb1 100644 --- a/sal/osl/w32/file_url.h +++ b/sal/osl/w32/file_url.h @@ -57,6 +57,7 @@ extern "C" { #define PATHTYPE_MASK_TYPE 0xFF #define PATHTYPE_IS_VOLUME 0x0100 #define PATHTYPE_IS_SERVER 0x0200 +#define PATHTYPE_IS_LONGPATH 0x0400 #define VALIDATEPATH_NORMAL 0x0000 #define VALIDATEPATH_ALLOW_WILDCARDS 0x0001 @@ -64,6 +65,8 @@ extern "C" { #define VALIDATEPATH_ALLOW_RELATIVE 0x0004 #define VALIDATEPATH_ALLOW_UNC 0x0008 +#define MAX_LONG_PATH 32767 + DWORD IsValidFilePath ( rtl_uString * path, LPCTSTR * lppError, @@ -74,7 +77,8 @@ DWORD IsValidFilePath ( DWORD GetCaseCorrectPathName ( LPCTSTR lpszShortPath, // file name LPTSTR lpszLongPath, // path buffer - DWORD cchBuffer // size of path buffer + DWORD cchBuffer, // size of path buffer + BOOL bCheckExistence ); oslFileError _osl_getSystemPathFromFileURL ( diff --git a/sal/osl/w32/module.c b/sal/osl/w32/module.cxx index 2d001fc425bb..57711e973b73 100644 --- a/sal/osl/w32/module.c +++ b/sal/osl/w32/module.cxx @@ -32,11 +32,15 @@ #include "system.h" #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) @@ -312,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_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; } } @@ -426,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_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..145fab8e7435 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,45 @@ 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 ) + { + OSL_ENSURE( m_pBuffer, "Can not allocate the buffer!" ); + } + + ~LongPathBuffer() + { + if ( m_pBuffer ) + 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 1412282f76c3..705b151d9505 100644 --- a/sal/osl/w32/process.c +++ b/sal/osl/w32/process.cxx @@ -46,6 +46,8 @@ #include "procimpl.h" #include "sockimpl.h" +#include "file_url.h" +#include "path_helper.hxx" #include <rtl/ustrbuf.h> #include <rtl/alloc.h> @@ -75,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; } @@ -219,19 +221,19 @@ oslProcessError SAL_CALL osl_joinProcessWithTimeout(oslProcess Process, const Ti * ***************************************************************************/ -oslProcessError SAL_CALL osl_bootstrap_getExecutableFile_Impl ( +extern "C" oslProcessError SAL_CALL osl_bootstrap_getExecutableFile_Impl ( rtl_uString ** ppFileURL ) SAL_THROW_EXTERN_C() { oslProcessError result = osl_Process_E_NotFound; - TCHAR buffer[MAX_PATH]; - DWORD buflen; + ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + DWORD buflen = 0; - if ((buflen = GetModuleFileNameW (0, buffer, MAX_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. */ @@ -285,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_PATH]; + ::osl::LongPathBuffer< sal_Unicode > aBuffer( MAX_LONG_PATH ); + DWORD dwResult = 0; dwResult = SearchPath ( - 0, ppArgs[0]->buffer, L".exe", MAX_PATH, szBuffer, 0); - if ((0 < dwResult) && (dwResult < MAX_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) @@ -414,24 +416,24 @@ oslProcessError SAL_CALL osl_getEnvironment(rtl_uString *ustrVar, rtl_uString ** * Current Working Directory. ***************************************************************************/ -extern oslMutex g_CurrentDirectoryMutex; +extern "C" oslMutex g_CurrentDirectoryMutex; oslProcessError SAL_CALL osl_getProcessWorkingDir( rtl_uString **pustrWorkingDir ) { - TCHAR szBuffer[MAX_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 ); @@ -449,7 +451,7 @@ oslProcessError SAL_CALL osl_getProcessWorkingDir( rtl_uString **pustrWorkingDir * Process Locale. ***************************************************************************/ -extern void _imp_getProcessLocale( rtl_Locale ** ppLocale ); +extern "C" void _imp_getProcessLocale( rtl_Locale ** ppLocale ); static rtl_Locale * g_theProcessLocale = NULL; diff --git a/sal/osl/w32/profile.c b/sal/osl/w32/profile.cxx index 59697e7fd698..583faeac90ef 100644 --- a/sal/osl/w32/profile.c +++ b/sal/osl/w32/profile.cxx @@ -31,6 +31,9 @@ #include "system.h" +#include "file_url.h" +#include "path_helper.hxx" + #include <osl/diagnose.h> #include <osl/profile.h> #include <osl/process.h> @@ -502,10 +505,10 @@ sal_Bool SAL_CALL osl_readProfileString(oslProfile Profile, } else { - CHAR szFileName[MAX_PATH]; + ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_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); @@ -683,10 +686,10 @@ sal_Bool SAL_CALL osl_writeProfileString(oslProfile Profile, } else { - CHAR szFileName[MAX_PATH]; + ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_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); @@ -794,10 +797,10 @@ sal_Bool SAL_CALL osl_removeProfileEntry(oslProfile Profile, } else { - CHAR szFileName[MAX_PATH]; + ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_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); @@ -868,10 +871,10 @@ sal_uInt32 SAL_CALL osl_getProfileSectionEntries(oslProfile Profile, const sal_C } else { - CHAR szFileName[MAX_PATH]; + ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_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); @@ -887,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_PATH]; - sal_Unicode wcsPath[MAX_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; @@ -898,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_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_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); } } @@ -937,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_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_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 */ @@ -972,10 +975,10 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, if (bFailed) return (sal_False); - if (strHome->length >= MAX_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)) @@ -983,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_PATH) + if (nLen + nPathLen >= aPath.getBufSizeInSymbols()) return sal_False; - wcscpy(wcsPath + nPathLen, pPath); + wcscpy(aPath + nPathLen, pPath); nPathLen += nLen; } @@ -1004,10 +1007,10 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName, if (bFailed) return (sal_False); - if (strConfig->length >= MAX_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)) @@ -1015,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_PATH) + if (nLen + nPathLen >= aPath.getBufSizeInSymbols()) return sal_False; - wcscpy(wcsPath + nPathLen, pPath); + wcscpy(aPath + nPathLen, pPath); nPathLen += nLen; } @@ -1028,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_PATH)) == 0) || (nPathLen >= MAX_PATH)) + if (((nPathLen = GetWindowsDirectoryW(aPath, aPath.getBufSizeInSymbols())) == 0) || (nPathLen >= aPath.getBufSizeInSymbols())) return (sal_False); if (nLen > RTL_CONSTASCII_LENGTH(STR_INI_METASYS)) @@ -1036,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_PATH) + if (nLen + nPathLen >= aPath.getBufSizeInSymbols()) return sal_False; - wcscpy(wcsPath + nPathLen, pPath); + wcscpy(aPath + nPathLen, pPath); nPathLen += nLen; } } @@ -1048,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_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; @@ -1071,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_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_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); @@ -1140,10 +1143,10 @@ sal_uInt32 SAL_CALL osl_getProfileSections(oslProfile Profile, sal_Char* pszBuff } else { - CHAR szFileName[MAX_PATH]; + ::osl::LongPathBuffer< sal_Char > aFileName( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_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); @@ -1154,35 +1157,6 @@ sal_uInt32 SAL_CALL osl_getProfileSections(oslProfile Profile, sal_Char* pszBuff - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /*****************************************************************************/ /* Static Module Functions */ /*****************************************************************************/ @@ -1287,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 ) )*/ @@ -2226,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; } @@ -2333,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_PATH] = L""; + ::osl::LongPathBuffer< sal_Unicode > aPath( MAX_LONG_PATH ); + aPath[0] = 0; DWORD dwPathLen = 0; if (*strPath == L'"') @@ -2367,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_PATH]; + ::osl::LongPathBuffer< sal_Char > aDir( MAX_LONG_PATH ); oslProfile hProfile; rtl_uString_newFromAscii(&strSVFallback, SVERSION_FALLBACK); @@ -2393,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); } } @@ -2428,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); } } @@ -2472,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_PATH]; + ::osl::LongPathBuffer< sal_Char > aTmpPath( MAX_LONG_PATH ); int n; - if ((n = WideCharToMultiByte(CP_ACP,0, wcsPath, -1, szPath, MAX_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_PATH - dwPathLen ); + dwPathLen += MultiByteToWideChar( CP_ACP, 0, SVERSION_USER, -1, aPath + dwPathLen, aPath.getBufSizeInSymbols() - dwPathLen ); } } } @@ -2536,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 */ @@ -2561,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_PATH]; + ::osl::LongPathBuffer< sal_Char > aTmpPath( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, wcsPath, -1, szPath, MAX_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) @@ -2592,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_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); } @@ -2612,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_PATH]; + ::osl::LongPathBuffer< sal_Char > aTmpPath( MAX_LONG_PATH ); - WideCharToMultiByte(CP_ACP,0, wcsPath, -1, szPath, MAX_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; @@ -2674,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_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_PATH]; + ::osl::LongPathBuffer< sal_Char > aTmpPath( MAX_LONG_PATH ); int n; if ((n = WideCharToMultiByte( - CP_ACP,0, wcsPath, -1, szPath, - MAX_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_PATH - dwPathLen ); + aPath + dwPathLen, + aPath.getBufSizeInSymbols() - dwPathLen ); } } } @@ -2721,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 9aabe453aa78..755ac86c7abf 100644 --- a/sal/osl/w32/signal.c +++ b/sal/osl/w32/signal.cxx @@ -32,6 +32,9 @@ #include "system.h" #include <tchar.h> +#include "file_url.h" +#include "path_helper.hxx" + #include <osl/diagnose.h> #include <osl/mutex.h> #include <osl/signal.h> @@ -115,7 +118,7 @@ static BOOL ReportCrash( LPEXCEPTION_POINTERS lpEP ) BOOL fSuccess = FALSE; BOOL fAutoReport = FALSE; TCHAR szBuffer[1024]; - TCHAR szPath[MAX_PATH]; + ::osl::LongPathBuffer< sal_Char > aPath( MAX_LONG_PATH ); LPTSTR lpFilePart; PROCESS_INFORMATION ProcessInfo; STARTUPINFO StartupInfo; @@ -167,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; @@ -180,7 +183,7 @@ static BOOL ReportCrash( LPEXCEPTION_POINTERS lpEP ) } } - if ( SearchPath( NULL, TEXT("crashrep.exe"), NULL, MAX_PATH, szPath, &lpFilePart ) ) + if ( SearchPath( NULL, TEXT( "crashrep.exe" ), NULL, aPath.getBufSizeInSymbols(), aPath, &lpFilePart ) ) { ZeroMemory( &StartupInfo, sizeof(StartupInfo) ); StartupInfo.cb = sizeof(StartupInfo.cb); @@ -188,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(), @@ -317,6 +320,8 @@ static long WINAPI SignalHandlerFunction(LPEXCEPTION_POINTERS lpEP) SetErrorMode(SEM_NOGPFAULTERRORBOX); exit(255); break; + default: + break; } return (EXCEPTION_CONTINUE_EXECUTION); @@ -334,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/system.h b/sal/osl/w32/system.h index 6e1cebc3aa93..8c40fbc78f84 100644 --- a/sal/osl/w32/system.h +++ b/sal/osl/w32/system.h @@ -108,10 +108,22 @@ #endif // #ifdef GCC #ifdef _DLL_ + +#ifdef __cplusplus + extern "C" DWORD g_dwPlatformId; +#else extern DWORD g_dwPlatformId; +#endif // #ifdef __cplusplus + #define IS_NT (g_dwPlatformId == VER_PLATFORM_WIN32_NT) #else + +#ifdef __cplusplus + extern "C" DWORD GetPlatformId(void); +#else extern DWORD GetPlatformId(void); +#endif // #ifdef __cplusplus + #define IS_NT (GetPlatformId() == VER_PLATFORM_WIN32_NT) #endif // #ifdef _DLL_ diff --git a/sal/osl/w32/tempfile.cxx b/sal/osl/w32/tempfile.cxx index 6c591eae8972..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" @@ -215,7 +216,7 @@ oslFileError SAL_CALL osl_createTempFile( if (osl_File_E_None != osl_error) return osl_error; - /* allocate enough space on the stack */ + /* allocate enough space on the stack, the file name can not be longer than MAX_PATH */ STACK_ALLOC(tmp_name, WCHAR, (rtl_uString_getLength(base_directory) + MAX_PATH)); if (tmp_name) @@ -241,25 +242,21 @@ oslFileError SAL_CALL osl_createTempFile( //############################################# oslFileError SAL_CALL osl_getTempDirURL(rtl_uString** pustrTempDir) { - WCHAR szBuffer[MAX_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; } + diff --git a/sal/rtl/source/ustring.c b/sal/rtl/source/ustring.c index bfe9a7c5f2bd..b938caf0d4b1 100644 --- a/sal/rtl/source/ustring.c +++ b/sal/rtl/source/ustring.c @@ -558,7 +558,12 @@ static void rtl_string2UString_status( rtl_uString** ppThis, "rtl_string2UString_status() - Wrong TextEncoding" ); if ( !nLen ) + { rtl_uString_new( ppThis ); + if (pInfo != NULL) { + *pInfo = 0; + } + } else { if ( *ppThis ) @@ -589,6 +594,9 @@ static void rtl_string2UString_status( rtl_uString** ppThis, nLen--; } while ( nLen ); + if (pInfo != NULL) { + *pInfo = 0; + } } else { |