From 365615a07ea528324818c89cf2447fbebf8fb95d Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Mon, 29 Oct 2007 23:30:49 +0000 Subject: On Mac, include TargetConditionals.h and architecture/byte_order.h, and use OSSwapInt{16,32,64} for SWAP* macros. Add k5_htonll and k5_ntohll functions. (Implementation assumes the swapping is its own reverse on all platforms we support.) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20150 dc483132-0cff-0310-8789-dd5450dbe970 --- src/include/k5-platform.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'src/include') diff --git a/src/include/k5-platform.h b/src/include/k5-platform.h index a143ab52a..b0d3e3af2 100644 --- a/src/include/k5-platform.h +++ b/src/include/k5-platform.h @@ -54,6 +54,10 @@ #define CAN_COPY_VA_LIST #endif +#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__)) +#include +#endif + /* Initialization and finalization function support for libraries. At top level, before the functions are defined or even declared: @@ -510,6 +514,12 @@ typedef struct { int error; unsigned char did_run; } k5_init_t; # define SWAP64 bswap_64 # endif #endif +#if TARGET_OS_MAC +# include +# define SWAP16 OSSwapInt16 +# define SWAP32 OSSwapInt32 +# define SWAP64 OSSwapInt64 +#endif static inline void store_16_be (unsigned int val, unsigned char *p) @@ -698,6 +708,24 @@ load_64_n (const unsigned char *p) return n; } +/* Assume for simplicity that these swaps are identical. */ +static inline UINT64_TYPE +k5_htonll (UINT64_TYPE val) +{ +#ifdef K5_BE + return val; +#elif defined K5_LE && defined SWAP64 + return SWAP64 (val); +#else + return load_64_be ((unsigned char *)&val); +#endif +} +static inline UINT64_TYPE +k5_ntohll (UINT64_TYPE val) +{ + return k5_htonll (val); +} + /* Make the interfaces to getpwnam and getpwuid consistent. Model the wrappers on the POSIX thread-safe versions, but use the unsafe system versions if the safe ones don't exist -- cgit