On Mac, include TargetConditionals.h and architecture/byte_order.h,
authorKen Raeburn <raeburn@mit.edu>
Mon, 29 Oct 2007 23:30:49 +0000 (23:30 +0000)
committerKen Raeburn <raeburn@mit.edu>
Mon, 29 Oct 2007 23:30:49 +0000 (23:30 +0000)
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

index a143ab52a600d4b367ce0dfdb4f363a64acb48da..b0d3e3af204cb5e243cea7ac01b02b9146c2fbb2 100644 (file)
 #define CAN_COPY_VA_LIST
 #endif
 
+#if defined(macintosh) || (defined(__MACH__) && defined(__APPLE__))
+#include <TargetConditionals.h>
+#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 <architecture/byte_order.h>
+# 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