Kaydet (Commit) efb74ad1 authored tarafından Kenneth Venken's avatar Kenneth Venken Kaydeden (comit) Norbert Thiebaud

use SAL_N_ELEMENTS macro

üst 3124c2d6
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
#include "file_error_transl.h" #include "file_error_transl.h"
#include "file_url.h" #include "file_url.h"
#include <sal/macros.h>
#include "file_path_helper.hxx" #include "file_path_helper.hxx"
#include "uunxapi.hxx" #include "uunxapi.hxx"
...@@ -824,7 +825,7 @@ oslFileError SAL_CALL _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uS ...@@ -824,7 +825,7 @@ oslFileError SAL_CALL _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uS
/* Indicates local root */ /* Indicates local root */
if ( nDecodedLen == nSkip ) if ( nDecodedLen == nSkip )
rtl_uString_newFromStr_WithLength( &strTempPath, (const sal_Unicode*)WSTR_SYSTEM_ROOT_PATH, ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1 ); rtl_uString_newFromStr_WithLength( &strTempPath, (const sal_Unicode*)WSTR_SYSTEM_ROOT_PATH, SAL_N_ELEMENTS(WSTR_SYSTEM_ROOT_PATH) - 1 );
else else
rtl_uString_newFromStr_WithLength( &strTempPath, pDecodedURL + nSkip, nDecodedLen - nSkip ); rtl_uString_newFromStr_WithLength( &strTempPath, pDecodedURL + nSkip, nDecodedLen - nSkip );
......
...@@ -51,8 +51,6 @@ const sal_Unicode UNICHAR_SLASH = ((sal_Unicode)'/'); ...@@ -51,8 +51,6 @@ const sal_Unicode UNICHAR_SLASH = ((sal_Unicode)'/');
const sal_Unicode UNICHAR_COLON = ((sal_Unicode)':'); const sal_Unicode UNICHAR_COLON = ((sal_Unicode)':');
const sal_Unicode UNICHAR_DOT = ((sal_Unicode)'.'); const sal_Unicode UNICHAR_DOT = ((sal_Unicode)'.');
#define ELEMENTS_OF_ARRAY(arr) (sizeof(arr)/(sizeof((arr)[0])))
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0
#define OSL_ENSURE_FILE( cond, msg, file ) ( (cond) ? (void)0 : _osl_warnFile( msg, file ) ) #define OSL_ENSURE_FILE( cond, msg, file ) ( (cond) ? (void)0 : _osl_warnFile( msg, file ) )
#else #else
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "osl/file.h" #include "osl/file.h"
#include "file_url.h" #include "file_url.h"
#include <sal/macros.h>
#include "file_error.h" #include "file_error.h"
#include "path_helper.hxx" #include "path_helper.hxx"
...@@ -146,7 +147,7 @@ namespace /* private */ ...@@ -146,7 +147,7 @@ namespace /* private */
//##################################################### //#####################################################
inline bool is_UNC_path(const sal_Unicode* path) inline bool is_UNC_path(const sal_Unicode* path)
{ return (0 == wcsncmp(UNC_PREFIX, reinterpret_cast<LPCWSTR>(path), ELEMENTS_OF_ARRAY(UNC_PREFIX) - 1)); } { return (0 == wcsncmp(UNC_PREFIX, reinterpret_cast<LPCWSTR>(path), SAL_N_ELEMENTS(UNC_PREFIX) - 1)); }
//##################################################### //#####################################################
inline bool is_UNC_path(const rtl::OUString& path) inline bool is_UNC_path(const rtl::OUString& path)
...@@ -1250,16 +1251,16 @@ bool is_floppy_volume_mount_point(const rtl::OUString& path) ...@@ -1250,16 +1251,16 @@ bool is_floppy_volume_mount_point(const rtl::OUString& path)
osl::systemPathEnsureSeparator(p); osl::systemPathEnsureSeparator(p);
TCHAR vn[51]; TCHAR vn[51];
if (GetVolumeNameForVolumeMountPoint(reinterpret_cast<LPCTSTR>(p.getStr()), vn, ELEMENTS_OF_ARRAY(vn))) if (GetVolumeNameForVolumeMountPoint(reinterpret_cast<LPCTSTR>(p.getStr()), vn, SAL_N_ELEMENTS(vn)))
{ {
TCHAR vnfloppy[51]; TCHAR vnfloppy[51];
if (is_floppy_A_present() && if (is_floppy_A_present() &&
GetVolumeNameForVolumeMountPoint(FLOPPY_A, vnfloppy, ELEMENTS_OF_ARRAY(vnfloppy)) && GetVolumeNameForVolumeMountPoint(FLOPPY_A, vnfloppy, SAL_N_ELEMENTS(vnfloppy)) &&
(0 == wcscmp(vn, vnfloppy))) (0 == wcscmp(vn, vnfloppy)))
return true; return true;
if (is_floppy_B_present() && if (is_floppy_B_present() &&
GetVolumeNameForVolumeMountPoint(FLOPPY_B, vnfloppy, ELEMENTS_OF_ARRAY(vnfloppy)) && GetVolumeNameForVolumeMountPoint(FLOPPY_B, vnfloppy, SAL_N_ELEMENTS(vnfloppy)) &&
(0 == wcscmp(vn, vnfloppy))) (0 == wcscmp(vn, vnfloppy)))
return true; return true;
} }
...@@ -1322,7 +1323,7 @@ static UINT get_volume_mount_point_drive_type(const rtl::OUString& path) ...@@ -1322,7 +1323,7 @@ static UINT get_volume_mount_point_drive_type(const rtl::OUString& path)
osl::systemPathEnsureSeparator(p); osl::systemPathEnsureSeparator(p);
TCHAR vn[51]; TCHAR vn[51];
if (GetVolumeNameForVolumeMountPoint(reinterpret_cast<LPCTSTR>(p.getStr()), vn, ELEMENTS_OF_ARRAY(vn))) if (GetVolumeNameForVolumeMountPoint(reinterpret_cast<LPCTSTR>(p.getStr()), vn, SAL_N_ELEMENTS(vn)))
return GetDriveType(vn); return GetDriveType(vn);
return DRIVE_NO_ROOT_DIR; return DRIVE_NO_ROOT_DIR;
...@@ -1573,7 +1574,7 @@ static oslFileError SAL_CALL osl_getDriveInfo( ...@@ -1573,7 +1574,7 @@ static oslFileError SAL_CALL osl_getDriveInfo(
case DRIVE_REMOTE: case DRIVE_REMOTE:
{ {
TCHAR szBuffer[1024]; TCHAR szBuffer[1024];
DWORD const dwBufsizeConst = ELEMENTS_OF_ARRAY(szBuffer); DWORD const dwBufsizeConst = SAL_N_ELEMENTS(szBuffer);
DWORD dwBufsize = dwBufsizeConst; DWORD dwBufsize = dwBufsizeConst;
DWORD dwResult = WNetGetConnection( cDrive, szBuffer, &dwBufsize ); DWORD dwResult = WNetGetConnection( cDrive, szBuffer, &dwBufsize );
...@@ -1592,7 +1593,7 @@ static oslFileError SAL_CALL osl_getDriveInfo( ...@@ -1592,7 +1593,7 @@ static oslFileError SAL_CALL osl_getDriveInfo(
case DRIVE_FIXED: case DRIVE_FIXED:
{ {
TCHAR szVolumeNameBuffer[1024]; TCHAR szVolumeNameBuffer[1024];
DWORD const dwBufsizeConst = ELEMENTS_OF_ARRAY(szVolumeNameBuffer); DWORD const dwBufsizeConst = SAL_N_ELEMENTS(szVolumeNameBuffer);
if ( GetVolumeInformation( cRoot, szVolumeNameBuffer, dwBufsizeConst, NULL, NULL, NULL, NULL, 0 ) ) if ( GetVolumeInformation( cRoot, szVolumeNameBuffer, dwBufsizeConst, NULL, NULL, NULL, NULL, 0 ) )
{ {
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "systools/win32/uwinapi.h" #include "systools/win32/uwinapi.h"
#include "file_url.h" #include "file_url.h"
#include <sal/macros.h>
#include "file_error.h" #include "file_error.h"
#include "rtl/alloc.h" #include "rtl/alloc.h"
...@@ -50,8 +51,6 @@ ...@@ -50,8 +51,6 @@
#define OSL_ENSURE_FILE( cond, msg, file ) ((void)0) #define OSL_ENSURE_FILE( cond, msg, file ) ((void)0)
#endif #endif
#define ELEMENTS_OF_ARRAY(arr) (sizeof(arr)/(sizeof((arr)[0])))
#define WSTR_SYSTEM_ROOT_PATH L"\\\\.\\" #define WSTR_SYSTEM_ROOT_PATH L"\\\\.\\"
#define WSTR_LONG_PATH_PREFIX L"\\\\?\\" #define WSTR_LONG_PATH_PREFIX L"\\\\?\\"
#define WSTR_LONG_PATH_PREFIX_UNC L"\\\\?\\UNC\\" #define WSTR_LONG_PATH_PREFIX_UNC L"\\\\?\\UNC\\"
...@@ -259,16 +258,16 @@ DWORD IsValidFilePath(rtl_uString *path, LPCTSTR *lppError, DWORD dwFlags, rtl_u ...@@ -259,16 +258,16 @@ DWORD IsValidFilePath(rtl_uString *path, LPCTSTR *lppError, DWORD dwFlags, rtl_u
DWORD dwCandidatPathType = PATHTYPE_ERROR; DWORD dwCandidatPathType = PATHTYPE_ERROR;
if ( 0 == rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( path->buffer, nLength, reinterpret_cast<const sal_Unicode *>(WSTR_LONG_PATH_PREFIX_UNC), ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX_UNC) - 1, ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX_UNC) - 1 ) ) if ( 0 == rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( path->buffer, nLength, reinterpret_cast<const sal_Unicode *>(WSTR_LONG_PATH_PREFIX_UNC), SAL_N_ELEMENTS(WSTR_LONG_PATH_PREFIX_UNC) - 1, SAL_N_ELEMENTS(WSTR_LONG_PATH_PREFIX_UNC) - 1 ) )
{ {
/* This is long path in UNC notation */ /* This is long path in UNC notation */
lpComponent = lpszPath + ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX_UNC) - 1; lpComponent = lpszPath + SAL_N_ELEMENTS(WSTR_LONG_PATH_PREFIX_UNC) - 1;
dwCandidatPathType = PATHTYPE_ABSOLUTE_UNC | PATHTYPE_IS_LONGPATH; dwCandidatPathType = PATHTYPE_ABSOLUTE_UNC | PATHTYPE_IS_LONGPATH;
} }
else if ( 0 == rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( path->buffer, nLength, reinterpret_cast<const sal_Unicode *>(WSTR_LONG_PATH_PREFIX), ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX) - 1, ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX) - 1 ) ) else if ( 0 == rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( path->buffer, nLength, reinterpret_cast<const sal_Unicode *>(WSTR_LONG_PATH_PREFIX), SAL_N_ELEMENTS(WSTR_LONG_PATH_PREFIX) - 1, SAL_N_ELEMENTS(WSTR_LONG_PATH_PREFIX) - 1 ) )
{ {
/* This is long path */ /* This is long path */
lpComponent = lpszPath + ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX) - 1; lpComponent = lpszPath + SAL_N_ELEMENTS(WSTR_LONG_PATH_PREFIX) - 1;
if ( _istalpha( lpComponent[0] ) && ':' == lpComponent[1] ) if ( _istalpha( lpComponent[0] ) && ':' == lpComponent[1] )
{ {
...@@ -562,14 +561,14 @@ DWORD GetCaseCorrectPathName( ...@@ -562,14 +561,14 @@ DWORD GetCaseCorrectPathName(
/* Special handling for "\\.\" as system root */ /* Special handling for "\\.\" as system root */
if ( lpszShortPath && 0 == wcscmp( lpszShortPath, WSTR_SYSTEM_ROOT_PATH ) ) if ( lpszShortPath && 0 == wcscmp( lpszShortPath, WSTR_SYSTEM_ROOT_PATH ) )
{ {
if ( cchBuffer >= ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) ) if ( cchBuffer >= SAL_N_ELEMENTS(WSTR_SYSTEM_ROOT_PATH) )
{ {
wcscpy( lpszLongPath, WSTR_SYSTEM_ROOT_PATH ); wcscpy( lpszLongPath, WSTR_SYSTEM_ROOT_PATH );
return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1; return SAL_N_ELEMENTS(WSTR_SYSTEM_ROOT_PATH) - 1;
} }
else else
{ {
return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1; return SAL_N_ELEMENTS(WSTR_SYSTEM_ROOT_PATH) - 1;
} }
} }
else if ( lpszShortPath ) else if ( lpszShortPath )
...@@ -773,7 +772,7 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p ...@@ -773,7 +772,7 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p
/* Indicates local root */ /* Indicates local root */
if ( nDecodedLen == nSkip ) 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 ); rtl_uString_newFromStr_WithLength( &strTempPath, reinterpret_cast<const sal_Unicode*>(WSTR_SYSTEM_ROOT_PATH), SAL_N_ELEMENTS(WSTR_SYSTEM_ROOT_PATH) - 1 );
else else
{ {
/* do not separate the directory and file case, so the maximal path lengs without prefix is MAX_PATH-12 */ /* do not separate the directory and file case, so the maximal path lengs without prefix is MAX_PATH-12 */
...@@ -790,8 +789,8 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p ...@@ -790,8 +789,8 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p
sal_False ); sal_False );
if ( nNewLen <= MAX_PATH - 12 if ( nNewLen <= MAX_PATH - 12
|| 0 == rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL + nSkip, nDecodedLen - nSkip, reinterpret_cast<const sal_Unicode*>(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, reinterpret_cast<const sal_Unicode*>(WSTR_SYSTEM_ROOT_PATH), SAL_N_ELEMENTS(WSTR_SYSTEM_ROOT_PATH) - 1, SAL_N_ELEMENTS(WSTR_SYSTEM_ROOT_PATH) - 1 )
|| 0 == rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL + nSkip, nDecodedLen - nSkip, reinterpret_cast<const sal_Unicode*>(WSTR_LONG_PATH_PREFIX), ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX) - 1, ELEMENTS_OF_ARRAY(WSTR_LONG_PATH_PREFIX) - 1 ) ) || 0 == rtl_ustr_shortenedCompareIgnoreAsciiCase_WithLength( pDecodedURL + nSkip, nDecodedLen - nSkip, reinterpret_cast<const sal_Unicode*>(WSTR_LONG_PATH_PREFIX), SAL_N_ELEMENTS(WSTR_LONG_PATH_PREFIX) - 1, SAL_N_ELEMENTS(WSTR_LONG_PATH_PREFIX) - 1 ) )
{ {
rtl_uString_newFromStr_WithLength( &strTempPath, aBuf, nNewLen ); rtl_uString_newFromStr_WithLength( &strTempPath, aBuf, nNewLen );
} }
...@@ -800,7 +799,7 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p ...@@ -800,7 +799,7 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p
/* it should be an UNC path, use the according prefix */ /* it should be an UNC path, use the according prefix */
rtl_uString *strSuffix = NULL; rtl_uString *strSuffix = NULL;
rtl_uString *strPrefix = NULL; rtl_uString *strPrefix = NULL;
rtl_uString_newFromStr_WithLength( &strPrefix, reinterpret_cast<const sal_Unicode*>(WSTR_LONG_PATH_PREFIX_UNC), ELEMENTS_OF_ARRAY( WSTR_LONG_PATH_PREFIX_UNC ) - 1 ); rtl_uString_newFromStr_WithLength( &strPrefix, reinterpret_cast<const sal_Unicode*>(WSTR_LONG_PATH_PREFIX_UNC), SAL_N_ELEMENTS( WSTR_LONG_PATH_PREFIX_UNC ) - 1 );
rtl_uString_newFromStr_WithLength( &strSuffix, aBuf + 2, nNewLen - 2 ); rtl_uString_newFromStr_WithLength( &strSuffix, aBuf + 2, nNewLen - 2 );
rtl_uString_newConcat( &strTempPath, strPrefix, strSuffix ); rtl_uString_newConcat( &strTempPath, strPrefix, strSuffix );
...@@ -812,7 +811,7 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p ...@@ -812,7 +811,7 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p
{ {
rtl_uString *strSuffix = NULL; rtl_uString *strSuffix = NULL;
rtl_uString *strPrefix = NULL; rtl_uString *strPrefix = NULL;
rtl_uString_newFromStr_WithLength( &strPrefix, reinterpret_cast<const sal_Unicode*>(WSTR_LONG_PATH_PREFIX), ELEMENTS_OF_ARRAY( WSTR_LONG_PATH_PREFIX ) - 1 ); rtl_uString_newFromStr_WithLength( &strPrefix, reinterpret_cast<const sal_Unicode*>(WSTR_LONG_PATH_PREFIX), SAL_N_ELEMENTS( WSTR_LONG_PATH_PREFIX ) - 1 );
rtl_uString_newFromStr_WithLength( &strSuffix, aBuf, nNewLen ); rtl_uString_newFromStr_WithLength( &strSuffix, aBuf, nNewLen );
rtl_uString_newConcat( &strTempPath, strPrefix, strSuffix ); rtl_uString_newConcat( &strTempPath, strPrefix, strSuffix );
...@@ -881,7 +880,7 @@ oslFileError _osl_getFileURLFromSystemPath( rtl_uString* strPath, rtl_uString** ...@@ -881,7 +880,7 @@ oslFileError _osl_getFileURLFromSystemPath( rtl_uString* strPath, rtl_uString**
switch ( dwPathType & PATHTYPE_MASK_TYPE ) switch ( dwPathType & PATHTYPE_MASK_TYPE )
{ {
case PATHTYPE_ABSOLUTE_UNC: case PATHTYPE_ABSOLUTE_UNC:
nIgnore = ELEMENTS_OF_ARRAY( WSTR_LONG_PATH_PREFIX_UNC ) - 1; nIgnore = SAL_N_ELEMENTS( WSTR_LONG_PATH_PREFIX_UNC ) - 1;
OSL_ENSURE( nIgnore == 8, "Unexpected long path UNC prefix!" ); OSL_ENSURE( nIgnore == 8, "Unexpected long path UNC prefix!" );
/* generate the normal UNC path */ /* generate the normal UNC path */
...@@ -894,7 +893,7 @@ oslFileError _osl_getFileURLFromSystemPath( rtl_uString* strPath, rtl_uString** ...@@ -894,7 +893,7 @@ oslFileError _osl_getFileURLFromSystemPath( rtl_uString* strPath, rtl_uString**
break; break;
case PATHTYPE_ABSOLUTE_LOCAL: case PATHTYPE_ABSOLUTE_LOCAL:
nIgnore = ELEMENTS_OF_ARRAY( WSTR_LONG_PATH_PREFIX ) - 1; nIgnore = SAL_N_ELEMENTS( WSTR_LONG_PATH_PREFIX ) - 1;
OSL_ENSURE( nIgnore == 4, "Unexpected long path prefix!" ); OSL_ENSURE( nIgnore == 4, "Unexpected long path prefix!" );
/* generate the normal path */ /* generate the normal path */
......
...@@ -43,8 +43,6 @@ ...@@ -43,8 +43,6 @@
#include <tchar.h> #include <tchar.h>
//##################################################### //#####################################################
#define ELEMENTS_OF_ARRAY(arr) (sizeof(arr)/(sizeof((arr)[0])))
// Allocate n number of t's on the stack return a pointer to it in p // Allocate n number of t's on the stack return a pointer to it in p
#ifdef __MINGW32__ #ifdef __MINGW32__
#define STACK_ALLOC(p, t, n) (p) = reinterpret_cast<t*>(_alloca((n)*sizeof(t))); #define STACK_ALLOC(p, t, n) (p) = reinterpret_cast<t*>(_alloca((n)*sizeof(t)));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment