Author: mturk Date: Fri Sep 4 09:16:49 2009 New Revision: 811313 URL: http://svn.apache.org/viewvc?rev=811313&view=rev Log: Add countof macro
Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr.h commons/sandbox/runtime/trunk/src/main/native/shared/error.c Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr.h URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr.h?rev=811313&r1=811312&r2=811313&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/include/acr.h (original) +++ commons/sandbox/runtime/trunk/src/main/native/include/acr.h Fri Sep 4 09:16:49 2009 @@ -282,6 +282,9 @@ /** Default alignment */ #define ACR_ALIGN_DEFAULT(size) ACR_ALIGN(size, 8) +/** Number of elements in static array */ +#define ACR_COUNTOF(a) (sizeof((a)) / sizeof((a)[0])) + /** * ACR_DECLARE_EXPORT is defined when building the ANNEX dynamic library, * so that all public symbols are exported. Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=811313&r1=811312&r2=811313&view=diff ============================================================================== --- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original) +++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Fri Sep 4 09:16:49 2009 @@ -513,7 +513,7 @@ errno = 0; return; } - for (i = 0; i < (sizeof(_psx_errlist) / sizeof(_psx_errlist[0])); i++) { + for (i = 0; i < ACR_COUNTOF(_psx_errlist); i++) { if (oserror == (int)_psx_errlist[i].win32_error) { errno = _psx_errlist[i].posix_error; break; @@ -530,7 +530,7 @@ if ((os = GetLastError())) return os + ACR_OS_START_SYSERR; crt = errno; - for (i = 0; crt, i < (sizeof(_psx_errlist) / sizeof(_psx_errlist[0])); i++) { + for (i = 0; crt, i < ACR_COUNTOF(_psx_errlist); i++) { if (crt == _psx_errlist[i].posix_error) return _psx_errlist[i].win32_error; }