]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
* k5-platform.h: New header file. Manages inline-function and 64-bit support,
authorKen Raeburn <raeburn@mit.edu>
Thu, 25 Sep 2003 07:17:51 +0000 (07:17 +0000)
committerKen Raeburn <raeburn@mit.edu>
Thu, 25 Sep 2003 07:17:51 +0000 (07:17 +0000)
in platform-specific ways.
* fake-addrinfo.h: Include k5-platform.h.
(inline): Don't define here.
* k5-int.h: Include k5-platform.h.
(krb5_ui_8, krb5_int64): New typedefs.
(krb5_ser_pack_int64, krb5_ser_unpack_int64): New function decls.

git-svn-id: svn://anonsvn.mit.edu/krb5/branches/raeburn-gssapi-cfx@15823 dc483132-0cff-0310-8789-dd5450dbe970

src/include/ChangeLog
src/include/fake-addrinfo.h
src/include/k5-int.h
src/include/k5-platform.h [new file with mode: 0644]

index 4614d3a14a247b074a2e87dc229ad0c9508a4bfb..f9071f2411eca8e2186eb71ec35618cb92c1a0ae 100644 (file)
@@ -1,3 +1,13 @@
+2003-09-25  Ken Raeburn  <raeburn@mit.edu>
+
+       * k5-platform.h: New header file.  Manages inline-function and
+       64-bit support, in platform-specific ways.
+       * fake-addrinfo.h: Include k5-platform.h.
+       (inline): Don't define here.
+       * k5-int.h: Include k5-platform.h.
+       (krb5_ui_8, krb5_int64): New typedefs.
+       (krb5_ser_pack_int64, krb5_ser_unpack_int64): New function decls.
+
 2003-09-12  Ken Raeburn  <raeburn@mit.edu>
 
        * configure.in: Check for setsid() and <paths.h>.
index e620357da2d66768d5d5d281b25a73d686876d93..9d122e392d2e5008718e860931b646d6341c0f98 100644 (file)
 #define FAI_DEFINED
 #include "port-sockets.h"
 #include "socket-utils.h"
-
-#if !defined(inline)
-# if __STDC_VERSION__ >= 199901L
-/* C99 supports inline, don't do anything.  */
-# elif defined(__GNUC__)
-#  define inline __inline__ /* this form silences -pedantic warnings */
-# elif defined(__mips) && defined(__sgi)
-#  define inline __inline /* IRIX used at MIT does inline but not c99 yet */
-# elif defined(__sun) && __SUNPRO_C >= 0x540
-/* The Forte Developer 7 C compiler supports "inline".  */
-# else
-#  define inline /* nothing, just static */
-# endif
-# define ADDRINFO_UNDEF_INLINE
-#endif
+#include "k5-platform.h"
 
 #ifdef S_SPLINT_S
 /*@-incondefs@*/
index 0cb1aeecb7ac35c4f63e34ce503612d4972aa770..f6a30e9689c452de527a1fa3d8d5b8f2a48521f4 100644 (file)
@@ -136,6 +136,13 @@ typedef unsigned char      u_char;
 #endif /* HAVE_SYS_TYPES_H */
 #endif /* KRB5_SYSTYPES__ */
 
+
+#include "k5-platform.h"
+/* not used in krb5.h (yet) */
+typedef UINT64_TYPE krb5_ui_8;
+typedef INT64_TYPE krb5_int64;
+
+
 #define DEFAULT_PWD_STRING1 "Enter password"
 #define DEFAULT_PWD_STRING2 "Re-enter password for verification"
 
@@ -1579,6 +1586,11 @@ krb5_error_code KRB5_CALLCONV krb5_ser_unpack_int32
        (krb5_int32 *,
                krb5_octet **,
                size_t *);
+/* [De]serialize 8-byte integer */
+krb5_error_code KRB5_CALLCONV krb5_ser_pack_int64
+       (krb5_int64, krb5_octet **, size_t *);
+krb5_error_code KRB5_CALLCONV krb5_ser_unpack_int64
+       (krb5_int64 *, krb5_octet **, size_t *);
 /* [De]serialize byte string */
 krb5_error_code KRB5_CALLCONV krb5_ser_pack_bytes
        (krb5_octet *,
diff --git a/src/include/k5-platform.h b/src/include/k5-platform.h
new file mode 100644 (file)
index 0000000..b5bccb6
--- /dev/null
@@ -0,0 +1,136 @@
+/* Copyright 2003 Massachusetts Institute of Technology.  All rights reserved.  */
+/* Platform-dependent junk.  */
+
+#ifndef K5_PLATFORM_H
+#define K5_PLATFORM_H
+
+#if !defined(inline)
+# if __STDC_VERSION__ >= 199901L
+/* C99 supports inline, don't do anything.  */
+# elif defined(__GNUC__)
+#  define inline __inline__ /* this form silences -pedantic warnings */
+# elif defined(__mips) && defined(__sgi)
+#  define inline __inline /* IRIX used at MIT does inline but not c99 yet */
+# elif defined(__sun) && __SUNPRO_C >= 0x540
+/* The Forte Developer 7 C compiler supports "inline".  */
+# elif defined(_WIN32)
+#  define inline __inline
+# else
+#  define inline /* nothing, just static */
+# endif
+#endif
+
+#include "autoconf.h"
+
+/* 64-bit support: krb5_ui_8 and krb5_int64.
+
+   This should move to krb5.h eventually, but without the namespace
+   pollution from the autoconf macros.  */
+#if defined(HAVE_STDINT_H) || defined(HAVE_INTTYPES_H)
+# ifdef HAVE_STDINT_H
+#  include <stdint.h>
+# endif
+# ifdef HAVE_INTTYPES_H
+#  include <inttypes.h>
+# endif
+# define INT64_TYPE int64_t
+# define UINT64_TYPE uint64_t
+#elif defined(_WIN32)
+# define INT64_TYPE signed __int64
+# define UINT64_TYPE unsigned __int64
+#else /* not Windows, and neither stdint.h nor inttypes.h */
+# define INT64_TYPE signed long long
+# define UINT64_TYPE unsigned long long
+#endif
+
+/* Read and write integer values as (unaligned) octet strings in
+   specific byte orders.
+
+   Add per-platform optimizations later if needed.  (E.g., maybe x86
+   unaligned word stores and gcc/asm instructions for byte swaps,
+   etc.)  */
+
+static inline void
+store_16_be (unsigned short val, unsigned char *p)
+{
+    p[0] = (val >>  8) & 0xff;
+    p[1] = (val      ) & 0xff;
+}
+static inline void
+store_16_le (unsigned short val, unsigned char *p)
+{
+    p[1] = (val >>  8) & 0xff;
+    p[0] = (val      ) & 0xff;
+}
+static inline void
+store_32_be (unsigned int val, unsigned char *p)
+{
+    p[0] = (val >> 24) & 0xff;
+    p[1] = (val >> 16) & 0xff;
+    p[2] = (val >>  8) & 0xff;
+    p[3] = (val      ) & 0xff;
+}
+static inline void
+store_32_le (unsigned int val, unsigned char *p)
+{
+    p[3] = (val >> 24) & 0xff;
+    p[2] = (val >> 16) & 0xff;
+    p[1] = (val >>  8) & 0xff;
+    p[0] = (val      ) & 0xff;
+}
+static inline void
+store_64_be (UINT64_TYPE val, unsigned char *p)
+{
+    p[0] = (val >> 56) & 0xff;
+    p[1] = (val >> 48) & 0xff;
+    p[2] = (val >> 40) & 0xff;
+    p[3] = (val >> 32) & 0xff;
+    p[4] = (val >> 24) & 0xff;
+    p[5] = (val >> 16) & 0xff;
+    p[6] = (val >>  8) & 0xff;
+    p[7] = (val      ) & 0xff;
+}
+static inline void
+store_64_le (UINT64_TYPE val, unsigned char *p)
+{
+    p[7] = (val >> 56) & 0xff;
+    p[6] = (val >> 48) & 0xff;
+    p[5] = (val >> 40) & 0xff;
+    p[4] = (val >> 32) & 0xff;
+    p[3] = (val >> 24) & 0xff;
+    p[2] = (val >> 16) & 0xff;
+    p[1] = (val >>  8) & 0xff;
+    p[0] = (val      ) & 0xff;
+}
+static inline unsigned short
+load_16_be (unsigned char *p)
+{
+    return (p[1] | (p[0] << 8));
+}
+static inline unsigned short
+load_16_le (unsigned char *p)
+{
+    return (p[0] | (p[1] << 8));
+}
+static inline unsigned int
+load_32_be (unsigned char *p)
+{
+    return (p[3] | (p[2] << 8) | (p[1] << 16) | (p[0] << 24));
+}
+static inline unsigned int
+load_32_le (unsigned char *p)
+{
+    return (p[0] | (p[1] << 8) | (p[2] << 16) | (p[3] << 24));
+}
+static inline UINT64_TYPE
+load_64_be (unsigned char *p)
+{
+    return ((unsigned long long)load_32_be(p) << 32) | load_32_be(p+4);
+}
+static inline UINT64_TYPE
+load_64_le (unsigned char *p)
+{
+    return ((unsigned long long)load_32_le(p+4) << 32) | load_32_le(p);
+}
+
+#endif /* K5_PLATFORM_H */