compat.h revision 1.1
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 42size_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#ifndef HAVE_UUID_H 78/* Length of a node address (an IEEE 802 address). */ 79#define _UUID_NODE_LEN 6 80 81/* 82 * See also: 83 * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt 84 * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm 85 * 86 * A DCE 1.1 compatible source representation of UUIDs. 87 */ 88typedef struct uuid_t { 89 uint32_t time_low; 90 uint16_t time_mid; 91 uint16_t time_hi_and_version; 92 uint8_t clock_seq_hi_and_reserved; 93 uint8_t clock_seq_low; 94 uint8_t node[_UUID_NODE_LEN]; 95} uuid_t; 96 97void uuid_create(uuid_t *, uint32_t *); 98void uuid_to_string(uuid_t *, char **, uint32_t *); 99#endif 100 101#endif /* COMPAT_H_ */ 102