1 #ifndef COMPAT_H_ 2 #define COMPAT_H_ 3 4 #include "config.h" 5 6 #include <sys/types.h> 7 8 #ifdef HAVE_STDINT_H 9 #include <stdint.h> 10 #endif 11 12 #ifdef HAVE_ASM_BYTEORDER_H 13 #include <asm/byteorder.h> 14 #endif 15 16 #ifdef HAVE_SYS_BYTEORDER_H 17 # include <sys/byteorder.h> 18 # if defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN) 19 # undef _BIG_ENDIAN 20 # define _BIG_ENDIAN 4321 21 # define _BYTE_ORDER _BIG_ENDIAN 22 # elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN) 23 # undef _LITTLE_ENDIAN 24 # define _LITTLE_ENDIAN 1234 25 # define _BYTE_ORDER _LITTLE_ENDIAN 26 # endif 27 #endif 28 29 #ifdef HAVE_BYTESWAP_H 30 #include <byteswap.h> 31 #endif 32 33 #ifdef HAVE_MACHINE_ENDIAN_H 34 #include <machine/endian.h> 35 #endif 36 37 #ifdef HAVE_LIBKERN_OSBYTEORDER_H 38 #include <libkern/OSByteOrder.h> 39 #endif 40 41 #ifndef HAVE_STRLCPY 42 size_t strlcpy(char *, const char *, size_t); 43 #endif 44 45 #ifndef __UNCONST 46 #define __UNCONST(a) ((void *)(unsigned long)(const void *)(a)) 47 #endif 48 49 #ifdef HAVE_HTOBE64 50 # define ISCSI_HTOBE64(x) htobe64(x) 51 # define ISCSI_BE64TOH(x) be64toh(x) 52 #else 53 # if defined(HAVE_LIBKERN_OSBYTEORDER_H) 54 # define ISCSI_HTOBE64(x) (x) = OSSwapBigToHostInt64((u_int64_t)(x)) 55 # elif _BYTE_ORDER == _BIG_ENDIAN 56 # define ISCSI_HTOBE64(x) (x) 57 # elif defined(HAVE___BSWAP64) 58 # define ISCSI_HTOBE64(x) (x) = __bswap64((u_int64_t)(x)) 59 # else /* LITTLE_ENDIAN */ 60 # define ISCSI_HTOBE64(x) (((uint64_t)(ISCSI_NTOHL((uint32_t)(((x) << 32) >> 32))) << 32) | (uint32_t)ISCSI_NTOHL(((uint32_t)((x) >> 32)))) 61 # endif /* LITTLE_ENDIAN */ 62 # define ISCSI_BE64TOH(x) ISCSI_HTOBE64(x) 63 #endif 64 65 #ifndef _DIAGASSERT 66 # ifndef __static_cast 67 # define __static_cast(x,y) (x)y 68 # endif 69 #define _DIAGASSERT(e) (__static_cast(void,0)) 70 #endif 71 72 /* Added for busybox, which doesn't define INFTIM */ 73 #ifndef INFTIM 74 #define INFTIM -1 75 #endif 76 77 #endif /* COMPAT_H_ */ 78