[Libreoffice-commits] .: sal/osl
Norbert Thiebaud
nthiebaud at kemper.freedesktop.org
Sun Oct 17 15:00:49 PDT 2010
sal/osl/os2/file_url.cxx | 3 ++-
sal/osl/os2/file_url.h | 2 --
sal/osl/w32/file_dirvol.cxx | 15 ++++++++-------
sal/osl/w32/file_url.cxx | 31 +++++++++++++++----------------
sal/osl/w32/tempfile.cxx | 2 --
5 files changed, 25 insertions(+), 28 deletions(-)
New commits:
commit fa34d4833a5574db4f9c8c3114008e2ef0a40add
Author: Kenneth Venken <kenneth.venken at gmail.com>
Date: Sun Oct 17 16:50:44 2010 -0500
use SAL_N_ELEMENTS macro
diff --git a/sal/osl/os2/file_url.cxx b/sal/osl/os2/file_url.cxx
index 04d103a..6ea7490 100644
--- a/sal/osl/os2/file_url.cxx
+++ b/sal/osl/os2/file_url.cxx
@@ -52,6 +52,7 @@
#include "file_error_transl.h"
#include "file_url.h"
+#include <sal/macros.h>
#include "file_path_helper.hxx"
#include "uunxapi.hxx"
@@ -824,7 +825,7 @@ oslFileError SAL_CALL _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uS
/* Indicates local root */
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
rtl_uString_newFromStr_WithLength( &strTempPath, pDecodedURL + nSkip, nDecodedLen - nSkip );
diff --git a/sal/osl/os2/file_url.h b/sal/osl/os2/file_url.h
index f63580f..c0f950c 100644
--- a/sal/osl/os2/file_url.h
+++ b/sal/osl/os2/file_url.h
@@ -51,8 +51,6 @@ const sal_Unicode UNICHAR_SLASH = ((sal_Unicode)'/');
const sal_Unicode UNICHAR_COLON = ((sal_Unicode)':');
const sal_Unicode UNICHAR_DOT = ((sal_Unicode)'.');
-#define ELEMENTS_OF_ARRAY(arr) (sizeof(arr)/(sizeof((arr)[0])))
-
#if OSL_DEBUG_LEVEL > 0
#define OSL_ENSURE_FILE( cond, msg, file ) ( (cond) ? (void)0 : _osl_warnFile( msg, file ) )
#else
diff --git a/sal/osl/w32/file_dirvol.cxx b/sal/osl/w32/file_dirvol.cxx
index 3b8200c..dd10f01 100644
--- a/sal/osl/w32/file_dirvol.cxx
+++ b/sal/osl/w32/file_dirvol.cxx
@@ -34,6 +34,7 @@
#include "osl/file.h"
#include "file_url.h"
+#include <sal/macros.h>
#include "file_error.h"
#include "path_helper.hxx"
@@ -146,7 +147,7 @@ namespace /* private */
//#####################################################
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)
@@ -1250,16 +1251,16 @@ bool is_floppy_volume_mount_point(const rtl::OUString& path)
osl::systemPathEnsureSeparator(p);
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];
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)))
return true;
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)))
return true;
}
@@ -1322,7 +1323,7 @@ static UINT get_volume_mount_point_drive_type(const rtl::OUString& path)
osl::systemPathEnsureSeparator(p);
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 DRIVE_NO_ROOT_DIR;
@@ -1573,7 +1574,7 @@ static oslFileError SAL_CALL osl_getDriveInfo(
case DRIVE_REMOTE:
{
TCHAR szBuffer[1024];
- DWORD const dwBufsizeConst = ELEMENTS_OF_ARRAY(szBuffer);
+ DWORD const dwBufsizeConst = SAL_N_ELEMENTS(szBuffer);
DWORD dwBufsize = dwBufsizeConst;
DWORD dwResult = WNetGetConnection( cDrive, szBuffer, &dwBufsize );
@@ -1592,7 +1593,7 @@ static oslFileError SAL_CALL osl_getDriveInfo(
case DRIVE_FIXED:
{
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 ) )
{
diff --git a/sal/osl/w32/file_url.cxx b/sal/osl/w32/file_url.cxx
index 4c582b2..4dc1e64 100644
--- a/sal/osl/w32/file_url.cxx
+++ b/sal/osl/w32/file_url.cxx
@@ -32,6 +32,7 @@
#include "systools/win32/uwinapi.h"
#include "file_url.h"
+#include <sal/macros.h>
#include "file_error.h"
#include "rtl/alloc.h"
@@ -50,8 +51,6 @@
#define OSL_ENSURE_FILE( cond, msg, file ) ((void)0)
#endif
-#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\\"
@@ -259,16 +258,16 @@ DWORD IsValidFilePath(rtl_uString *path, LPCTSTR *lppError, DWORD dwFlags, rtl_u
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 */
- 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;
}
- 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 */
- 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] )
{
@@ -562,14 +561,14 @@ DWORD GetCaseCorrectPathName(
/* Special handling for "\\.\" as system root */
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 );
- return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1;
+ return SAL_N_ELEMENTS(WSTR_SYSTEM_ROOT_PATH) - 1;
}
else
{
- return ELEMENTS_OF_ARRAY(WSTR_SYSTEM_ROOT_PATH) - 1;
+ return SAL_N_ELEMENTS(WSTR_SYSTEM_ROOT_PATH) - 1;
}
}
else if ( lpszShortPath )
@@ -773,7 +772,7 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p
/* Indicates local root */
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
{
/* 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
sal_False );
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_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_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), SAL_N_ELEMENTS(WSTR_LONG_PATH_PREFIX) - 1, SAL_N_ELEMENTS(WSTR_LONG_PATH_PREFIX) - 1 ) )
{
rtl_uString_newFromStr_WithLength( &strTempPath, aBuf, nNewLen );
}
@@ -800,7 +799,7 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p
/* it should be an UNC path, use the according prefix */
rtl_uString *strSuffix = 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_newConcat( &strTempPath, strPrefix, strSuffix );
@@ -812,7 +811,7 @@ oslFileError _osl_getSystemPathFromFileURL( rtl_uString *strURL, rtl_uString **p
{
rtl_uString *strSuffix = 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_newConcat( &strTempPath, strPrefix, strSuffix );
@@ -881,7 +880,7 @@ oslFileError _osl_getFileURLFromSystemPath( rtl_uString* strPath, rtl_uString**
switch ( dwPathType & PATHTYPE_MASK_TYPE )
{
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!" );
/* generate the normal UNC path */
@@ -894,7 +893,7 @@ oslFileError _osl_getFileURLFromSystemPath( rtl_uString* strPath, rtl_uString**
break;
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!" );
/* generate the normal path */
diff --git a/sal/osl/w32/tempfile.cxx b/sal/osl/w32/tempfile.cxx
index 4b44981..2b43af0 100644
--- a/sal/osl/w32/tempfile.cxx
+++ b/sal/osl/w32/tempfile.cxx
@@ -43,8 +43,6 @@
#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
#ifdef __MINGW32__
#define STACK_ALLOC(p, t, n) (p) = reinterpret_cast<t*>(_alloca((n)*sizeof(t)));
More information about the Libreoffice-commits
mailing list