00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef _OSMACROS_H_
00026 #define _OSMACROS_H_
00027
00028 #if defined(_MSC_VER)
00029
00030
00031 #pragma warning(disable: 4127)
00032 #endif
00033
00034
00035 #define OS_MAX(a,b) (((a)>(b))?(a):(b))
00036 #define OS_MIN(a,b) (((a)<(b))?(a):(b))
00037
00038
00039 #define OS_ISHEXCHAR(c) \
00040 ((c >= '0' && c <= '9') || (c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f'))
00041
00042
00043 #define OS_ISEMPTY(s) (s == 0 || *s == '\0')
00044
00045
00046 #define OS_HEXCHARTONIBBLE(ch,b) do { \
00047 if (ch >= '0' && ch <= '9') b = (unsigned char)(ch - '0'); \
00048 else if (ch >= 'a' && ch <= 'f') b = (unsigned char)((ch - 'a') + 10); \
00049 else if (ch >= 'A' && ch <= 'F') b = (unsigned char)((ch - 'A') + 10); \
00050 else b = 0xFF; } while(0)
00051
00052 #define OS_NIBBLETOHEXCHAR(b,ch) do { \
00053 if (b >= 0 && b <= 9) ch = (char)(b + '0'); \
00054 else if (b >= 0x0a && b <= 0x0f) ch = (char)((b - 10)+ 'a'); \
00055 else ch = '?'; } while(0)
00056
00062 #define OSRTARRAYSIZE(x) (sizeof(x)/sizeof(x[0]))
00063
00067 #define OSUTF8(str) ((const OSUTF8CHAR*)str)
00068
00072 #define OSUTF8LEN(str) strlen((const char*)str)
00073
00074
00075
00076 #define ForAllIter(p,listIter,type) \
00077 for(listIter.setFirst(),p=(type)listIter.getCurrentItem();!listIter.isDone();\
00078 listIter.setNext(),p=(type)listIter.getCurrentItem())
00079
00080 #define ForAllIterRev(p,listIter,type) \
00081 for(listIter.setLast(),p=(type)listIter.getCurrentItem();!listIter.isDone();\
00082 listIter.setPrev(),p=(type)listIter.getCurrentItem())
00083
00084
00085
00086 #define UTF8CHAR_SIZE 1
00087
00088
00089
00090 #include <stdio.h>
00091 #include <stdarg.h>
00092
00093 #if defined(_MSC_VER)
00094 # if _MSC_VER >= 1400
00095 # define os_snprintf(str, size, ...) \
00096 _snprintf_s(str, size, _TRUNCATE, __VA_ARGS__)
00097 # define os_vsnprintf(str, size, fmt, ...) \
00098 _vsnprintf_s(str, size, _TRUNCATE, fmt, __VA_ARGS__)
00099 # else
00100 # define os_snprintf _snprintf
00101 # define os_vsnprintf _vsnprintf
00102 # endif
00103 #elif defined(__HP_aCC)
00104
00105 # define os_snprintf(str, size, ...) sprintf(str, __VA_ARGS__)
00106 # define os_vsnprintf(str, size, fmt, ...) \
00107 vsnprintf(str, size, (char *)fmt, __VA_ARGS__)
00108 #elif defined(_NO_SNPRINTF_) && !defined(__vxworks) && !defined (__SYMBIAN32__)
00109 #define os_snprintf(str, size, ...) sprintf(str, __VA_ARGS__)
00110 #define os_vsnprintf(str, size, fmt, ...) vsprintf(str, fmt, __VA_ARGS__)
00111
00112 #elif defined(__vxworks) || defined(__SYMBIAN32__)
00113 #define os_snprintf(str,size,ARGS...) sprintf(str,##ARGS)
00114 #define os_vsnprintf(str,size,fmt,ARGS...) vsprintf(str,fmt,##ARGS)
00115 #else
00116 #define os_snprintf snprintf
00117 #define os_vsnprintf vsnprintf
00118 #endif
00119
00120 #endif
00121