summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikhail Voytenko <mav@openoffice.org>2010-01-26 17:42:23 +0100
committerMikhail Voytenko <mav@openoffice.org>2010-01-26 17:42:23 +0100
commita376e767439b370a757514bdda3f74d9102d0c81 (patch)
treefdbca979078918109b484ca8c8df21a1421d0a4d
parent3bea77ef4e7ef1a5f0ed58128d536554330f1dd3 (diff)
#i50885# Long path support for Windows
-rw-r--r--sal/osl/w32/file_dirvol.cxx208
-rw-r--r--sal/osl/w32/file_url.cxx293
-rw-r--r--sal/osl/w32/file_url.h3
-rw-r--r--sal/osl/w32/module.c6
-rw-r--r--sal/osl/w32/process.c13
-rw-r--r--sal/osl/w32/profile.c80
-rw-r--r--sal/osl/w32/signal.c6
-rw-r--r--sal/osl/w32/tempfile.cxx4
8 files changed, 349 insertions, 264 deletions
diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx
index 441a571ed..918192000 100644
--- a/sal/osl/w32/file_dirvol.cxx
+++ b/sal/osl/w32/file_dirvol.cxx
@@ -294,7 +294,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 +313,7 @@ struct Directory_Impl
HANDLE hDirectory;
HANDLE hEnumDrives;
};
- TCHAR szDirectoryPath[MAX_PATH];
+ rtl_uString* m_pDirectoryPath;
};
//#####################################################
@@ -398,34 +398,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 +516,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 +551,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 +581,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 +647,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 +665,7 @@ 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))
+ if (CreateDirectory( reinterpret_cast<LPCTSTR>( rtl_uString_getStr( dir_path ) ), NULL) )
{
if (aDirectoryCreationCallbackFunc)
{
@@ -865,6 +918,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 +957,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 +1035,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 +1102,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,9 +1165,10 @@ 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!
+ // if it is necessary in future, the system call GetLongPathName() should be used instead
// GetCaseCorrectPathName( pItemImpl->szFullPath, pItemImpl->szFullPath, sizeof(pItemImpl->szFullPath) );
pItemImpl->uType = DIRECTORYITEM_FILE;
@@ -1133,7 +1208,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 +1431,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 +1649,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 +1678,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 +1738,44 @@ 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 );
+ sal_Unicode* pBuffer = reinterpret_cast<sal_Unicode*>( rtl_allocateMemory( sizeof(sal_Unicode) * ( nLen + 1 ) ) );
+ if ( pBuffer )
+ {
+ sal_uInt32 nNewLen = GetLongPathName( reinterpret_cast<LPCTSTR>( rtl_uString_getStr( pItemImpl->m_pFullPath ) ),
+ pBuffer,
+ nLen );
+ if ( nNewLen > nLen )
+ {
+ rtl_freeMemory( pBuffer );
+ pBuffer = reinterpret_cast<sal_Unicode*>( rtl_allocateMemory( sizeof(sal_Unicode*) * ( nNewLen + 1 ) ) );
+ if ( pBuffer )
+ {
+ sal_uInt32 nNewestLen = GetLongPathName( reinterpret_cast<LPCTSTR>( rtl_uString_getStr( pItemImpl->m_pFullPath ) ),
+ pBuffer,
+ nNewLen );
+ if ( nNewLen == nNewestLen )
+ rtl_uString_newFromStr( &pItemImpl->m_pFullPath, reinterpret_cast< const sal_Unicode* >( pBuffer ) );
+ }
+ }
+ else
+ rtl_uString_newFromStr( &pItemImpl->m_pFullPath, reinterpret_cast< const sal_Unicode* >( pBuffer ) );
+
+ rtl_freeMemory( pBuffer );
+ 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 d4fc62c07..93a791d94 100644
--- a/sal/osl/w32/file_url.cxx
+++ b/sal/osl/w32/file_url.cxx
@@ -52,6 +52,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 +73,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 +240,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 +324,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 +341,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 +357,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;
}
@@ -408,135 +430,6 @@ static BOOL PathRemoveFileSpec(LPTSTR lpPath)
return fSuccess;
}
-//#####################################################
-// Undocumented in SHELL32.DLL ordinal 32
-static LPTSTR PathAddBackslash(LPTSTR lpPath)
-{
- LPTSTR lpEndPath = NULL;
-
- if ( lpPath )
- {
- int nLen = _tcslen(lpPath);
-
- if ( !nLen || lpPath[nLen-1] != '\\' && lpPath[nLen-1] != '/' && nLen < MAX_PATH - 1 )
- {
- lpEndPath = lpPath + nLen;
- *lpEndPath++ = '\\';
- *lpEndPath = 0;
- }
- }
- return lpEndPath;
-}
-
-//#####################################################
-// Same as GetLongPathName but also 95/NT4
-static DWORD GetCaseCorrectPathNameEx(
- LPCTSTR lpszShortPath, // file name
- LPTSTR lpszLongPath, // path buffer
- DWORD cchBuffer, // size of path buffer
- DWORD nSkipLevels
-)
-{
- TCHAR szPath[MAX_PATH];
- BOOL fSuccess;
-
- cchBuffer = cchBuffer; /* avoid warnings */
-
- _tcscpy( szPath, lpszShortPath );
-
- fSuccess = PathRemoveFileSpec( szPath );
-
- if ( fSuccess )
- {
- int nLen = _tcslen( szPath );
- LPCTSTR lpszFileSpec = lpszShortPath + nLen;
- BOOL bSkipThis;
-
- if ( 0 == _tcscmp( lpszFileSpec, TEXT("..") ) )
- {
- bSkipThis = TRUE;
- nSkipLevels += 1;
- }
- else if (
- 0 == _tcscmp( lpszFileSpec, TEXT(".") ) ||
- 0 == _tcscmp( lpszFileSpec, TEXT("\\") ) ||
- 0 == _tcscmp( lpszFileSpec, TEXT("/") )
- )
- {
- bSkipThis = TRUE;
- }
- else if ( nSkipLevels )
- {
- bSkipThis = TRUE;
- nSkipLevels--;
- }
- else
- bSkipThis = FALSE;
-
- GetCaseCorrectPathNameEx( szPath, szPath, MAX_PATH, nSkipLevels );
-
- PathAddBackslash( szPath );
-
- /* 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) )
- {
- _tcscat( szPath, aFindFileData.cFileName[0] ? aFindFileData.cFileName : aFindFileData.cAlternateFileName );
-
- FindClose( hFind );
- }
- else
- return 0;
- }
- }
- else
- {
- /* File specification can't be removed therefore the short path is either a drive
- 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 );
- }
-
- _tcscpy( lpszLongPath, szPath );
-
- return _tcslen( lpszLongPath );
-}
-
-//#####################################################
-#define WSTR_SYSTEM_ROOT_PATH L"\\\\.\\"
-
-DWORD GetCaseCorrectPathName(
- LPCTSTR lpszShortPath, // file name
- LPTSTR lpszLongPath, // path buffer
- DWORD cchBuffer // size of path buffer
-)
-{
- /* Special handling for "\\.\" as system root */
- if ( lpszShortPath && 0 == wcscmp( lpszShortPath, WSTR_SYSTEM_ROOT_PATH ) )
- {
- if ( cchBuffer >= ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) )
- {
- wcscpy( lpszLongPath, WSTR_SYSTEM_ROOT_PATH );
- return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1;
- }
- else
- {
- return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1;
- }
- }
- else
- {
- return GetCaseCorrectPathNameEx( lpszShortPath, lpszLongPath, cchBuffer, 0 );
- }
-}
-
//#############################################
static sal_Bool _osl_decodeURL( rtl_String* strUTF8, rtl_uString** pstrDecodedURL )
{
@@ -670,7 +563,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 +620,53 @@ 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
+ {
+ if ( 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, pDecodedURL + nSkip, nDecodedLen - nSkip );
+ }
+ 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 ) );
+ rtl_uString_newFromStr_WithLength( &strSuffix, pDecodedURL + nSkip + 2, nDecodedLen - nSkip - 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 ) );
+ rtl_uString_newFromStr_WithLength( &strSuffix, pDecodedURL + nSkip + 2, nDecodedLen - nSkip - 2 );
+
+ 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 +709,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 );
+ 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 );
+ 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 +922,8 @@ oslFileError SAL_CALL osl_getAbsoluteFileURL( rtl_uString* ustrBaseURL, rtl_uStr
if ( !eError )
{
- TCHAR szBuffer[MAX_PATH];
- TCHAR szCurrentDir[MAX_PATH];
+ TCHAR szBuffer[MAX_LONG_PATH];
+ TCHAR szCurrentDir[MAX_LONG_PATH];
LPTSTR lpFilePart = NULL;
DWORD dwResult;
@@ -963,11 +938,11 @@ oslFileError SAL_CALL osl_getAbsoluteFileURL( rtl_uString* ustrBaseURL, rtl_uStr
{
osl_acquireMutex( g_CurrentDirectoryMutex );
- GetCurrentDirectory( MAX_PATH, szCurrentDir );
+ GetCurrentDirectory( MAX_LONG_PATH, szCurrentDir );
SetCurrentDirectory( reinterpret_cast<LPCTSTR>(ustrBaseSysPath->buffer) );
}
- dwResult = GetFullPathName( reinterpret_cast<LPCTSTR>(ustrRelSysPath->buffer), MAX_PATH, szBuffer, &lpFilePart );
+ dwResult = GetFullPathName( reinterpret_cast<LPCTSTR>(ustrRelSysPath->buffer), MAX_LONG_PATH, szBuffer, &lpFilePart );
if ( ustrBaseSysPath )
{
@@ -978,7 +953,7 @@ oslFileError SAL_CALL osl_getAbsoluteFileURL( rtl_uString* ustrBaseURL, rtl_uStr
if ( dwResult )
{
- if ( dwResult >= MAX_PATH )
+ if ( dwResult >= MAX_LONG_PATH )
eError = osl_File_E_INVAL;
else
{
diff --git a/sal/osl/w32/file_url.h b/sal/osl/w32/file_url.h
index c84dee255..711a3ff6c 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,
diff --git a/sal/osl/w32/module.c b/sal/osl/w32/module.c
index f09ae5773..f0a5a69ae 100644
--- a/sal/osl/w32/module.c
+++ b/sal/osl/w32/module.c
@@ -32,6 +32,8 @@
#include "system.h"
#include <tlhelp32.h>
+#include "file_url.h"
+
#include <osl/module.h>
#include <osl/diagnose.h>
#include <osl/thread.h>
@@ -312,7 +314,7 @@ static sal_Bool SAL_CALL _osl_addressGetModuleURL_NT4( void *pv, rtl_uString **p
if ( lpfnSymInitialize && lpfnSymCleanup && lpfnSymGetModuleInfo )
{
IMAGEHLP_MODULE ModuleInfo;
- CHAR szModuleFileName[MAX_PATH];
+ CHAR szModuleFileName[MAX_LONG_PATH];
LPSTR lpSearchPath = NULL;
if ( GetModuleFileNameA( NULL, szModuleFileName, sizeof(szModuleFileName) ) )
@@ -426,7 +428,7 @@ 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];
+ WCHAR szBuffer[MAX_LONG_PATH];
rtl_uString *ustrSysPath = NULL;
GetModuleFileNameW( lpModules[iModule], szBuffer, bufsizeof(szBuffer) );
diff --git a/sal/osl/w32/process.c b/sal/osl/w32/process.c
index cd61d9369..89f0869ba 100644
--- a/sal/osl/w32/process.c
+++ b/sal/osl/w32/process.c
@@ -46,6 +46,7 @@
#include "procimpl.h"
#include "sockimpl.h"
+#include "file_url.h"
#include <rtl/ustrbuf.h>
#include <rtl/alloc.h>
@@ -225,10 +226,10 @@ oslProcessError SAL_CALL osl_bootstrap_getExecutableFile_Impl (
{
oslProcessError result = osl_Process_E_NotFound;
- TCHAR buffer[MAX_PATH];
+ TCHAR buffer[MAX_LONG_PATH];
DWORD buflen;
- if ((buflen = GetModuleFileNameW (0, buffer, MAX_PATH)) > 0)
+ if ((buflen = GetModuleFileNameW (0, buffer, MAX_LONG_PATH)) > 0)
{
rtl_uString * pAbsPath = 0;
rtl_uString_newFromStr_WithLength (&(pAbsPath), buffer, buflen);
@@ -286,11 +287,11 @@ static rtl_uString ** osl_createCommandArgs_Impl (int argc, char ** argv)
{
/* Ensure absolute path */
DWORD dwResult;
- TCHAR szBuffer[MAX_PATH];
+ TCHAR szBuffer[MAX_LONG_PATH];
dwResult = SearchPath (
- 0, ppArgs[0]->buffer, L".exe", MAX_PATH, szBuffer, 0);
- if ((0 < dwResult) && (dwResult < MAX_PATH))
+ 0, ppArgs[0]->buffer, L".exe", MAX_LONG_PATH, szBuffer, 0);
+ if ((0 < dwResult) && (dwResult < MAX_LONG_PATH))
{
/* Replace argv[0] with it's absolute path */
rtl_uString_newFromStr_WithLength(
@@ -418,7 +419,7 @@ extern oslMutex g_CurrentDirectoryMutex;
oslProcessError SAL_CALL osl_getProcessWorkingDir( rtl_uString **pustrWorkingDir )
{
- TCHAR szBuffer[MAX_PATH];
+ TCHAR szBuffer[MAX_LONG_PATH];
DWORD dwLen;
diff --git a/sal/osl/w32/profile.c b/sal/osl/w32/profile.c
index 0457fbf3c..ce035aeee 100644
--- a/sal/osl/w32/profile.c
+++ b/sal/osl/w32/profile.c
@@ -31,6 +31,8 @@
#include "system.h"
+#include "file_url.h"
+
#include <osl/diagnose.h>
#include <osl/profile.h>
#include <osl/process.h>
@@ -502,9 +504,9 @@ sal_Bool SAL_CALL osl_readProfileString(oslProfile Profile,
}
else
{
- CHAR szFileName[MAX_PATH];
+ CHAR szFileName[MAX_LONG_PATH];
- WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_PATH, NULL, NULL);
+ WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_LONG_PATH, NULL, NULL);
GetPrivateProfileString(pszSection, pszEntry, pszDefault, pszString, MaxLen, szFileName);
}
@@ -683,9 +685,9 @@ sal_Bool SAL_CALL osl_writeProfileString(oslProfile Profile,
}
else
{
- CHAR szFileName[MAX_PATH];
+ CHAR szFileName[MAX_LONG_PATH];
- WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_PATH, NULL, NULL);
+ WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_LONG_PATH, NULL, NULL);
WritePrivateProfileString(pszSection, pszEntry, pszString, szFileName);
}
@@ -794,9 +796,9 @@ sal_Bool SAL_CALL osl_removeProfileEntry(oslProfile Profile,
}
else
{
- CHAR szFileName[MAX_PATH];
+ CHAR szFileName[MAX_LONG_PATH];
- WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_PATH, NULL, NULL);
+ WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_LONG_PATH, NULL, NULL);
WritePrivateProfileString(pszSection, pszEntry, NULL, szFileName);
}
@@ -868,9 +870,9 @@ sal_uInt32 SAL_CALL osl_getProfileSectionEntries(oslProfile Profile, const sal_C
}
else
{
- CHAR szFileName[MAX_PATH];
+ CHAR szFileName[MAX_LONG_PATH];
- WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_PATH, NULL, NULL);
+ WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_LONG_PATH, NULL, NULL);
n = GetPrivateProfileString(pszSection, NULL, NULL, pszBuffer, MaxLen, szFileName);
}
@@ -887,8 +889,8 @@ 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_Unicode wcsFile[MAX_LONG_PATH];
+ sal_Unicode wcsPath[MAX_LONG_PATH];
sal_uInt32 nFileLen;
sal_uInt32 nPathLen = 0;
@@ -898,7 +900,7 @@ 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(strName->length >= MAX_LONG_PATH)
return sal_False;
wcscpy(wcsFile, strName->buffer);
@@ -906,7 +908,7 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName,
if (rtl_ustr_indexOfChar( wcsFile, L'.' ) == -1)
{
- if (nFileLen + wcslen(STR_INI_EXTENSION) >= MAX_PATH)
+ if (nFileLen + wcslen(STR_INI_EXTENSION) >= MAX_LONG_PATH)
return sal_False;
/* add default extension */
@@ -937,12 +939,12 @@ 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) >= MAX_LONG_PATH)
return sal_False;
wcsncpy(wcsFile, pProgName + nOffset, nFileLen);
- if (nFileLen + wcslen(STR_INI_EXTENSION) >= MAX_PATH)
+ if (nFileLen + wcslen(STR_INI_EXTENSION) >= MAX_LONG_PATH)
return sal_False;
/* add default extension */
@@ -972,7 +974,7 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName,
if (bFailed) return (sal_False);
- if (strHome->length >= MAX_PATH)
+ if (strHome->length >= MAX_LONG_PATH)
return sal_False;
wcscpy( wcsPath, strHome->buffer);
@@ -983,7 +985,7 @@ 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 >= MAX_LONG_PATH)
return sal_False;
wcscpy(wcsPath + nPathLen, pPath);
@@ -1004,7 +1006,7 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName,
if (bFailed) return (sal_False);
- if (strConfig->length >= MAX_PATH)
+ if (strConfig->length >= MAX_LONG_PATH)
return sal_False;
wcscpy( wcsPath, strConfig->buffer);
@@ -1015,7 +1017,7 @@ 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 >= MAX_LONG_PATH)
return sal_False;
wcscpy(wcsPath + nPathLen, pPath);
@@ -1028,7 +1030,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(wcsPath, MAX_LONG_PATH)) == 0) || (nPathLen >= MAX_LONG_PATH))
return (sal_False);
if (nLen > RTL_CONSTASCII_LENGTH(STR_INI_METASYS))
@@ -1036,7 +1038,7 @@ 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 >= MAX_LONG_PATH)
return sal_False;
wcscpy(wcsPath + nPathLen, pPath);
@@ -1054,7 +1056,7 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName,
nPathLen = wcslen(wcsPath);
}
- else if(nLen < MAX_PATH)
+ else if(nLen < MAX_LONG_PATH)
{
wcscpy(wcsPath, pPath);
nPathLen = wcslen(wcsPath);
@@ -1071,7 +1073,7 @@ 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 (strConfigDir->length >= MAX_LONG_PATH)
return sal_False;
wcscpy(wcsPath, strConfigDir->buffer);
@@ -1084,7 +1086,7 @@ sal_Bool SAL_CALL osl_getProfileName(rtl_uString* strPath, rtl_uString* strName,
wcsPath[nPathLen] = 0;
}
- if (nPathLen + nFileLen >= MAX_PATH)
+ if (nPathLen + nFileLen >= MAX_LONG_PATH)
return sal_False;
/* append file name */
@@ -1140,9 +1142,9 @@ sal_uInt32 SAL_CALL osl_getProfileSections(oslProfile Profile, sal_Char* pszBuff
}
else
{
- CHAR szFileName[MAX_PATH];
+ CHAR szFileName[MAX_LONG_PATH];
- WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_PATH, NULL, NULL);
+ WideCharToMultiByte(CP_ACP,0, pProfile->m_strFileName->buffer, -1, szFileName, MAX_LONG_PATH, NULL, NULL);
n = GetPrivateProfileSectionNames(pszBuffer, MaxLen, szFileName);
}
@@ -2333,7 +2335,7 @@ 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"";
+ WCHAR wcsPath[MAX_LONG_PATH] = L"";
DWORD dwPathLen = 0;
if (*strPath == L'"')
@@ -2367,7 +2369,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];
+ sal_Char Dir[MAX_LONG_PATH];
oslProfile hProfile;
rtl_uString_newFromAscii(&strSVFallback, SVERSION_FALLBACK);
@@ -2488,15 +2490,15 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str
}
else
{
- CHAR szPath[MAX_PATH];
+ CHAR szPath[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, wcsPath, -1, szPath, MAX_LONG_PATH, NULL, NULL)) > 0)
{
strcpy(szPath + n, SVERSION_USER);
if (access(szPath, 0) >= 0)
{
- dwPathLen += MultiByteToWideChar( CP_ACP, 0, SVERSION_USER, -1, wcsPath + dwPathLen, MAX_PATH - dwPathLen );
+ dwPathLen += MultiByteToWideChar( CP_ACP, 0, SVERSION_USER, -1, wcsPath + dwPathLen, MAX_LONG_PATH - dwPathLen );
}
}
}
@@ -2572,9 +2574,9 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str
}
{
- CHAR szPath[MAX_PATH];
+ CHAR szPath[MAX_LONG_PATH];
- WideCharToMultiByte(CP_ACP,0, wcsPath, -1, szPath, MAX_PATH, NULL, NULL);
+ WideCharToMultiByte(CP_ACP,0, wcsPath, -1, szPath, MAX_LONG_PATH, NULL, NULL);
/* if file not exists, remove any specified subdirectories
like "bin" or "program" */
@@ -2598,7 +2600,7 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str
}
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, wcsPath + nPos + 1, MAX_LONG_PATH - (nPos + 1) );
}
}
else
@@ -2621,9 +2623,9 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str
wcscpy(wcsPath + dwPathLen, strFile);
{
- CHAR szPath[MAX_PATH];
+ CHAR szPath[MAX_LONG_PATH];
- WideCharToMultiByte(CP_ACP,0, wcsPath, -1, szPath, MAX_PATH, NULL, NULL);
+ WideCharToMultiByte(CP_ACP,0, wcsPath, -1, szPath, MAX_LONG_PATH, NULL, NULL);
if ((access(szPath, 0) < 0) && (strlen(Product) > 0))
{
@@ -2674,7 +2676,7 @@ 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, wcsPath, MAX_LONG_PATH );
dwPathLen -=1;
/* build full path */
@@ -2691,12 +2693,12 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str
}
else
{
- CHAR szPath[MAX_PATH];
+ CHAR szPath[MAX_LONG_PATH];
int n;
if ((n = WideCharToMultiByte(
CP_ACP,0, wcsPath, -1, szPath,
- MAX_PATH, NULL, NULL))
+ MAX_LONG_PATH, NULL, NULL))
> 0)
{
strcpy(szPath + n, SVERSION_USER);
@@ -2705,7 +2707,7 @@ static sal_Bool lookupProfile(const sal_Unicode *strPath, const sal_Unicode *str
dwPathLen += MultiByteToWideChar(
CP_ACP, 0, SVERSION_USER, -1,
wcsPath + dwPathLen,
- MAX_PATH - dwPathLen );
+ MAX_LONG_PATH - dwPathLen );
}
}
}
diff --git a/sal/osl/w32/signal.c b/sal/osl/w32/signal.c
index 0a4ecc344..003530cbb 100644
--- a/sal/osl/w32/signal.c
+++ b/sal/osl/w32/signal.c
@@ -32,6 +32,8 @@
#include "system.h"
#include <tchar.h>
+#include "file_url.h"
+
#include <osl/diagnose.h>
#include <osl/mutex.h>
#include <osl/signal.h>
@@ -115,7 +117,7 @@ static BOOL ReportCrash( LPEXCEPTION_POINTERS lpEP )
BOOL fSuccess = FALSE;
BOOL fAutoReport = FALSE;
TCHAR szBuffer[1024];
- TCHAR szPath[MAX_PATH];
+ TCHAR szPath[MAX_LONG_PATH];
LPTSTR lpFilePart;
PROCESS_INFORMATION ProcessInfo;
STARTUPINFO StartupInfo;
@@ -180,7 +182,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, MAX_LONG_PATH, szPath, &lpFilePart ) )
{
ZeroMemory( &StartupInfo, sizeof(StartupInfo) );
StartupInfo.cb = sizeof(StartupInfo.cb);
diff --git a/sal/osl/w32/tempfile.cxx b/sal/osl/w32/tempfile.cxx
index 708dbe15c..7383345e9 100644
--- a/sal/osl/w32/tempfile.cxx
+++ b/sal/osl/w32/tempfile.cxx
@@ -215,7 +215,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,7 +241,7 @@ oslFileError SAL_CALL osl_createTempFile(
//#############################################
oslFileError SAL_CALL osl_getTempDirURL(rtl_uString** pustrTempDir)
{
- WCHAR szBuffer[MAX_PATH];
+ WCHAR szBuffer[MAX_LONG_PATH];
LPWSTR lpBuffer = szBuffer;
DWORD nBufferLength = ELEMENTS_OF_ARRAY(szBuffer) - 1;