Return to pal CVS log | Up to [OMI] / omi / pal |
File: [OMI] / omi / pal / pal
(download)
Revision: 1.1, Mon Apr 20 17:19:55 2015 UTC (9 years ago) by krisbash Branch: MAIN CVS Tags: OMI_1_0_8_2, OMI_1_0_8_1, HEAD OMI 1.0.8-1 |
#ifndef _pal_palcommon_h #define _pal_palcommon_h #include <stdarg.h> #include <stddef.h> #include <stdlib.h> #include "string.h" #if defined(_MSC_VER) # include <windows.h> # include <windef.h> # include <windows.h> # include <strsafe.h> #else # include "../../common/linux/sal.h" #endif #include <limits.h> #ifndef NAME_MAX # define NAME_MAX 255 #endif /* **============================================================================== ** ** ATTN: windows specific types; get rid of them for PAL_* types ** **============================================================================== */ #ifdef _MSC_VER #ifndef WIN32_FROM_HRESULT #define WIN32_FROM_HRESULT(hr) (HRESULT_FACILITY(hr) == FACILITY_WIN32 ? HRESULT_CODE(hr) : hr) #endif #else #define WIN32_FROM_HRESULT(hr) hr #define HRESULT_FROM_WIN32(error) error typedef unsigned long DWORD, *LPDWORD; typedef int BOOL; typedef unsigned long HRESULT; typedef const wchar_t *PCWSTR; typedef wchar_t *PWSTR; typedef const char *PCSTR; typedef char *PSTR; typedef void *PVOID; typedef PVOID HANDLE; #define NO_ERROR 0 #define INFINITE 0xFFFFFFFF #define WINAPI #define S_OK 0 #define ERROR_GEN_FAILURE 31 #define TRUE 1 #define FALSE 0 #define ERROR_INVALID_PARAMETER 87 #define ERROR_OUTOFMEMORY 14 #define MAX_PATH 0x00000104 typedef unsigned long long uint64; #endif /* **============================================================================== ** ** Including config.h ** **============================================================================== */ #if defined(_MSC_VER) # include <pal/config.h> #else # include "config.h" #endif /* **============================================================================== ** ** __FUNCTION__ ** **============================================================================== */ #if !defined(CONFIG_HAVE_FUNCTION_MACRO) # define __FUNCTION__ "<unknown>" #endif /* **============================================================================== ** ** PAL_32BIT ** PAL_64BIT ** **============================================================================== */ #if defined(__GNUC__) # if defined(__i386__) # define PAL_32BIT # elif defined(__x86_64__) # define PAL_64BIT # elif defined(__ppc__) # define PAL_32BIT # elif defined(__ppc64__) # define PAL_64BIT # elif ((ULONG_MAX) == (UINT_MAX) && (ULONG_MAX == 0xFFFFFFFF)) # define PAL_32BIT # else # define PAL_64BIT # endif #elif defined(_MSC_VER) # if defined(_WIN64) # define PAL_64BIT # else # define PAL_32BIT # endif #elif ((ULONG_MAX) == (UINT_MAX) && (ULONG_MAX == 0xFFFFFFFF)) # define PAL_32BIT #else # define PAL_64BIT #endif /* **============================================================================== ** ** PAL_CALL macro ** **============================================================================== */ #ifdef _MSC_VER # define PAL_CALL __stdcall #else # define PAL_CALL #endif /* **============================================================================== ** ** PAL_EXPORT_API, PAL_IMPORT_API macros ** **============================================================================== */ #if defined(_MSC_VER) # define PAL_EXPORT_API __declspec(dllexport) # define PAL_IMPORT_API __declspec(dllimport) #elif defined(__GNUC__) # define PAL_EXPORT_API __attribute__((visibility("default"))) # define PAL_IMPORT_API /* empty */ #elif defined(sun) # define PAL_EXPORT_API __global # define PAL_IMPORT_API /* empty */ #else # define PAL_EXPORT_API /* empty */ # define PAL_IMPORT_API /* empty */ #endif /* **============================================================================== ** ** PAL_BEGIN_EXTERNC ** PAL_END_EXTERNC ** **============================================================================== */ #if defined(__cplusplus) # define PAL_BEGIN_EXTERNC extern "C" { # define PAL_END_EXTERNC } #else # define PAL_BEGIN_EXTERNC # define PAL_END_EXTERNC #endif /* **============================================================================== ** ** PAL_EXTERN_C ** **============================================================================== */ #ifdef __cplusplus # define PAL_EXTERN_C extern "C" #else # define PAL_EXTERN_C extern #endif /* __cplusplus */ /* **============================================================================== ** ** PAL_INLINE macro ** **============================================================================== */ #if defined(_MSC_VER) # define PAL_INLINE static __inline #elif defined(__GNUC__) # define PAL_INLINE static __inline #elif defined(sun) # define PAL_INLINE static inline #elif defined(aix) # define PAL_INLINE static inline #else # define PAL_INLINE static __inline #endif /* **============================================================================== ** ** PAL string ** **============================================================================== */ #if defined(CONFIG_ENABLE_WCHAR) typedef wchar_t PAL_Char; #else typedef char PAL_Char; #endif typedef PAL_Char TChar; /* **============================================================================== ** ** PAL_T() ** **============================================================================== */ #if defined(CONFIG_ENABLE_WCHAR) # define __PAL_T(STR) L ## STR # define PAL_T(STR) __PAL_T(STR) #else # define PAL_T(STR) STR #endif /* **============================================================================== ** ** PAL_UNUSED ** **============================================================================== */ #define PAL_UNUSED(X) ((void)X) /* **============================================================================== ** ** PAL_HAVE_POSIX ** **============================================================================== */ #if defined(linux) || defined(sun) || defined(hpux) || defined(aix) # define PAL_HAVE_POSIX #endif /* **============================================================================== ** ** PAL_HAVE_PTHREADS ** **============================================================================== */ #if defined(linux) | defined(sun) | defined(hpux) | defined(aix) # define PAL_HAVE_PTHREADS #endif /* **============================================================================== ** ** Basic types ** **============================================================================== */ typedef unsigned char PAL_Uint8; #define PAL_UINT8_MAX (UCHAR_MAX) typedef signed char PAL_Sint8; #define PAL_SINT8_MIN (SCHAR_MIN) #define PAL_SINT8_MAX (SCHAR_MAX) typedef unsigned short PAL_Uint16; #define PAL_UINT16_MAX (USHRT_MAX) typedef signed short PAL_Sint16; #define PAL_SINT16_MIN (SHRT_MIN) #define PAL_SINT16_MAX (SHRT_MAX) typedef unsigned int PAL_Uint32; #define PAL_UINT32_MAX (UINT_MAX) typedef signed int PAL_Sint32; #define PAL_SINT32_MIN (INT_MIN) #define PAL_SINT32_MAX (INT_MAX) #if defined(_MSC_VER) typedef unsigned __int64 PAL_Uint64; typedef signed __int64 PAL_Sint64; #else typedef unsigned long long PAL_Uint64; typedef signed long long PAL_Sint64; #endif #define PAL_UINT64_MIN ((PAL_Uint64) 0ULL) #define PAL_UINT64_MAX ((PAL_Uint64) 18446744073709551615ULL) #define PAL_SINT64_MIN ((PAL_Sint64) (-9223372036854775807LL - 1LL)) #define PAL_SINT64_MAX ((PAL_Sint64) 9223372036854775807LL ) typedef unsigned char PAL_Boolean; #define PAL_TRUE ((PAL_Boolean)1) #define PAL_FALSE ((PAL_Boolean)0) /* **============================================================================== ** ** Function calling conventions ** **============================================================================== */ #if defined(_MSC_VER) # define ATEXIT_API __cdecl #else # define ATEXIT_API #endif /* **============================================================================== ** ** SAL Notation for non-Windows ** **============================================================================== */ #if !defined(_MSC_VER) # ifndef _In_ # define _In_ # endif # ifndef _Out_ # define _Out_ # endif # ifndef _Inout_ # define _Inout_ # endif # ifndef _Return_type_success_ # define _Return_type_success_(x) # endif # ifndef _Acquires_lock_ # define _Acquires_lock_(x) # endif # ifndef _Releases_lock_ # define _Releases_lock_(x) # endif # ifndef _In_z_ # define _In_z_ # endif # ifndef _Post_z_ # define _Post_z_ # endif # ifndef _Out_writes_ # define _Out_writes_(size) # endif # ifndef _Out_writes_z_ # define _Out_writes_z_(size) # endif # ifndef _Null_terminated_ # define _Null_terminated_ # endif # ifndef _Use_decl_annotations_ # define _Use_decl_annotations_ # endif # ifndef _Out_opt_ # define _Out_opt_ # endif # ifndef _Deref_post_z_ # define _Deref_post_z_ # endif # ifndef _Inout_updates_z_ # define _Inout_updates_z_(count) # endif # ifndef _Inout_opt_z_ # define _Inout_opt_z_ # endif # ifndef _Deref_prepost_opt_z_ # define _Deref_prepost_opt_z_ # endif # ifndef _In_opt_ # define _In_opt_ # endif # ifndef _In_opt_z_ # define _In_opt_z_ # endif # ifndef _Ret_maybenull_ # define _Ret_maybenull_ # endif # ifndef _Check_return_ # define _Check_return_ # endif # ifndef _Must_inspect_result_ # define _Must_inspect_result_ # endif # ifndef _Frees_ptr_opt_ # define _Frees_ptr_opt_ # endif # ifndef _Frees_ptr_ # define _Frees_ptr_ # endif # ifndef _Const_ # define _Const_ # endif # ifndef _Post_writable_byte_size # define _Post_writable_byte_size(size) # endif # ifndef _Analysis_assume_ # define _Analysis_assume_(expr) # endif # ifndef _Always_ # define _Always_(expr) # endif # ifndef _Outptr_ # define _Outptr_ # endif # ifndef _Outptr_result_buffer_ # define _Outptr_result_buffer_(size) # endif # ifndef _Outptr_result_nullonfailure_ # define _Outptr_result_nullonfailure_ # endif # ifndef _Maybenull_ # define _Maybenull_ # endif # ifndef _Notnull_ # define _Notnull_ # endif # ifndef _Valid_ # define _Valid_ # endif # ifndef _Analysis_noreturn_ # define _Analysis_noreturn_ # endif # ifndef _Ret_writes_maybenull_z_ # define _Ret_writes_maybenull_z_(count) # endif # ifndef _String_length_ # define _String_length_(str) # endif # ifndef _Success_ # define _Success_ # endif # ifndef _Field_range_ # define _Field_range_(min, max) # endif # ifndef _In_range_ # define _In_range_(min, max) # endif # ifndef _Field_size_ # define _Field_size_(count) # endif # ifndef _Field_size_opt_ # define _Field_size_opt_(count) # endif # ifndef _Field_size_full_opt_ # define _Field_size_full_opt_(count) # endif # ifndef _Field_size_bytes_opt_ # define _Field_size_bytes_opt_(size) # endif # ifndef _Readable_elements_ # define _Readable_elements_(count) # endif # ifndef _Writable_elements_ # define _Writable_elements_(count) # endif # ifndef _Struct_size_bytes_ # define _Struct_size_bytes_(size) # endif # ifndef _At_ # define _At_(target, annotation) # endif # ifndef _Pre_satisfies_ # define _Pre_satisfies_(expr) # endif # ifndef _On_failure_ # define _On_failure_(expr) # endif # ifndef _In_bytecount_ # define _In_bytecount_(size) # endif # ifndef _Out_writes_bytes_to_opt_ # define _Out_writes_bytes_to_opt_(buffLen, bufferNeeded) # endif # ifndef _When_ # define _When_(expr, annotation) # endif # ifndef _Analysis_assume_nullterminated_ # define _Analysis_assume_nullterminated_(expr) # endif #endif /* !defined(_MSC_VER) */ /* **============================================================================== ** ** PAL_MAX_PATH_SIZE ** **============================================================================== */ #define PAL_MAX_PATH_SIZE 1024 /* **============================================================================== ** ** PAL_COUNT ** **============================================================================== */ #ifdef _MSC_VER # define PAL_COUNT(ARR) _countof(ARR) #else # define PAL_COUNT(ARR) (sizeof(ARR) / sizeof(ARR[0])) #endif /* **============================================================================== ** ** PAL_Timestamp (equivalent to MI_Timestamp) ** ** Represents a timestamp as described in the CIM Infrastructure ** specification ** ** [1] MI_ee DSP0004 (http://www.dmtf.org/standards/published_documents) ** **============================================================================== */ typedef struct _PAL_Timestamp { /* YYYYMMDDHHMMSS.MMMMMMSUTC */ PAL_Uint32 year; PAL_Uint32 month; PAL_Uint32 day; PAL_Uint32 hour; PAL_Uint32 minute; PAL_Uint32 second; PAL_Uint32 microseconds; PAL_Sint32 utc; } PAL_Timestamp; /* **============================================================================== ** ** struct PAL_Interval (equivalent to MI_Interval) ** ** Represents an interval as described in the CIM Infrastructure ** specification. This structure is padded to have the same length ** as a MI_Timestamp structure. ** ** [1] MI_ee DSP0004 (http://www.dmtf.org/standards/published_documents) ** **============================================================================== */ typedef struct _PAL_Interval { /* DDDDDDDDHHMMSS.MMMMMM:000 */ PAL_Uint32 days; PAL_Uint32 hours; PAL_Uint32 minutes; PAL_Uint32 seconds; PAL_Uint32 microseconds; PAL_Uint32 __padding1; PAL_Uint32 __padding2; PAL_Uint32 __padding3; } PAL_Interval; /* **============================================================================== ** ** struct PAL_Datetime (equivalent to MI_Datetime) ** ** Represents a CIM datetime type as described in the CIM Infrastructure ** specification. It contains a union of PAL_Timestamp and PAL_Interval. ** **============================================================================== */ typedef struct _PAL_Datetime { PAL_Uint32 isTimestamp; union { PAL_Timestamp timestamp; PAL_Interval interval; } u; } PAL_Datetime; /* **============================================================================== ** ** PAL_PREFETCH ** **============================================================================== */ #if defined(_MSC_VER) # define PAL_PREFETCH(p) ReadForWriteAccess(p) #elif defined(CONFIG_HAVE_BUILTIN_PREFETCH) # define PAL_PREFETCH(p) (__builtin_prefetch((const void*)p),*(p)) #else # define PAL_PREFETCH(p) (*p) #endif /* **============================================================================== ** ** PAL_STATIC_ASSERT ** ** Example usage: ** PAL_STATIC_ASSERT(sizeof(MI_CompositeDisposable) == sizeof(CompositeDisposable)) ** (ensures that size of a public struct (with 3 reserved ptrdiff_t fields) ** is the same as size of an internal struct) **============================================================================== */ #define PAL_STATIC_ASSERT(condition) \ typedef char _static_assert ## __LINE__ [(condition) ? 1 : -1] /* **============================================================================== ** ** PAL_tolower (same as tolower from C89's <ctype.h>, but operating on PAL_Char) ** **============================================================================== */ PAL_INLINE PAL_Char PAL_tolower(PAL_Char c) { if ((PAL_T('A') <= c) && (c <= PAL_T('Z'))) c += (PAL_T('a') - PAL_T('A')); return c; } /* **============================================================================== ** ** va_copy and other non-C89 helpers for vararg handling ** **============================================================================== */ #if defined(CONFIG_HAVE_VA_COPY) #define PAL_va_copy(dest, source) va_copy(dest, source) #else #define PAL_va_copy(dest, source) ((dest) = (source)) #endif PAL_BEGIN_EXTERNC #if defined(_MSC_VER) extern SECURITY_DESCRIPTOR g_SecurityDescriptor; extern SECURITY_ATTRIBUTES g_SecurityAttributes; #endif /* **============================================================================== ** ** Prefix to be used for unique semaphore/shmem names on non-Windows ** **============================================================================== */ #if !defined(_MSC_VER) # if defined(hpux) // HP-UX puts shared objects in files # define PAL_SHARED_OBJECT_PREFIX "/tmp/" # else # define PAL_SHARED_OBJECT_PREFIX "/" // Most UNIX/Linux require a leading '/' and no further '/' # endif # define PAL_UNIQUE_PREFIX PAL_SHARED_OBJECT_PREFIX CONFIG_UUID #endif PAL_END_EXTERNC #endif /* _pal_palcommon_h */
ViewCVS 0.9.2 |