libisdn
|
00001 00005 #ifndef __ASN1_COMMON_H__ 00006 #define __ASN1_COMMON_H__ 00007 00008 #ifdef PLATFORM_WINDOWS 00009 #define HEX_INT8_FMT "02hx" 00010 #else 00011 #define HEX_INT8_FMT "02hhx" 00012 #endif 00013 00014 #ifndef offset_of 00015 #define offset_of(type, member) \ 00016 (uintptr_t)&(((type *)0)->member) 00017 #endif 00018 00019 #ifndef container_of 00020 #define container_of(ptr, type, member) \ 00021 (type *)((uintptr_t)ptr - offset_of(type, member)) 00022 #endif 00023 00024 #ifndef MIN 00025 #define MIN(x, y) (((x) < (y)) ? (x) : (y)) 00026 #endif 00027 00028 #ifndef MAX 00029 #define MAX(x, y) (((x) > (y)) ? (x) : (y)) 00030 #endif 00031 00032 #ifndef ARRAY_SIZE 00033 #define ARRAY_SIZE(x) (sizeof((x)) / sizeof((x)[0])) 00034 #endif 00035 00036 #ifndef __packed 00037 #define __packed __attribute__((packed)) 00038 #endif 00039 00040 #ifndef __unused 00041 #define __unused __attribute__((unused)) 00042 #endif 00043 00044 #ifdef DEBUG 00045 void ____asn1_ptr_check(const char *file, const int line, void *ptr); 00046 void *_asn1_malloc(const long size); 00047 void _asn1_free(void *ptr); 00048 #define __asn1_ptr_check(ptr) \ 00049 ____asn1_ptr_check(__FILE__, __LINE__, ptr) 00050 #define asn1_malloc(size) _asn1_malloc(size) 00051 #define asn1_free(ptr) _asn1_free(ptr) 00052 #else 00053 #define __asn1_ptr_check(ptr) 00054 #define asn1_malloc(size) malloc(size) 00055 #define asn1_free(ptr) free(ptr) 00056 #endif 00057 00058 #endif /* __ASN1_COMMON_H__ */