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