]> git.draconx.ca Git - dxcommon.git/commitdiff
pack: Improve 64-bit detection.
authorNick Bowler <nbowler@draconx.ca>
Sat, 18 Nov 2023 20:28:10 +0000 (15:28 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sat, 18 Nov 2023 21:39:56 +0000 (16:39 -0500)
HP-UX 11.11 does not provide (U)LLONG_MAX in <limits.h>, but does provide
(U)LONG_LONG_MAX.  Tweak the check to find this, and also accept the
Autoconf-provided HAVE_LONG_LONG_INT so things just work if that is
used.

src/pack.h

index 26c25460da3fee5eb90e38f59605448e06a2eaa1..e14a10d9f502f06b7f9344da95b193f8121c46be 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2009 Nick Bowler
+ * Copyright © 2009, 2023 Nick Bowler
  *
  * Portable binary (de-)serialisation of integral types.
  *
 #ifndef DX_PACK_H_
 #define DX_PACK_H_
 
-#include <limits.h>
-#if !defined(PACK_HAVE_64BIT) && defined(ULLONG_MAX) && defined(LLONG_MAX)
-#      define PACK_HAVE_64BIT 1
+#ifndef PACK_HAVE_64BIT
+#  if HAVE_LONG_LONG_INT
+#    define PACK_HAVE_64BIT 1
+#  else
+#    include <limits.h>
+#    if defined(LLONG_MAX) || defined(LONG_LONG_MAX)
+#      define PACK_HAVE_64BIT 1
+#    endif
+#  endif
 #endif
 
+short unpack_s16_be(const unsigned char *);
+short unpack_s16_le(const unsigned char *);
+unsigned short unpack_16_be(const unsigned char *);
+unsigned short unpack_16_le(const unsigned char *);
 void pack_16_be(unsigned char *, unsigned short);
-void pack_32_be(unsigned char *, unsigned long);
-#if PACK_HAVE_64BIT
-void pack_64_be(unsigned char *, unsigned long long);
-#endif
-
 void pack_16_le(unsigned char *, unsigned short);
-void pack_32_le(unsigned char *, unsigned long);
-#if PACK_HAVE_64BIT
-void pack_64_le(unsigned char *, unsigned long long);
-#endif
 
-unsigned short unpack_16_be(const unsigned char *);
-unsigned long  unpack_32_be(const unsigned char *);
-#if PACK_HAVE_64BIT
-unsigned long long unpack_64_be(const unsigned char *);
-#endif
-
-unsigned short unpack_16_le(const unsigned char *);
-unsigned long  unpack_32_le(const unsigned char *);
-#if PACK_HAVE_64BIT
-unsigned long long unpack_64_le(const unsigned char *);
-#endif
+long unpack_s32_be(const unsigned char *);
+long unpack_s32_le(const unsigned char *);
+unsigned long unpack_32_be(const unsigned char *);
+unsigned long unpack_32_le(const unsigned char *);
+void pack_32_be(unsigned char *, unsigned long);
+void pack_32_le(unsigned char *, unsigned long);
 
-short unpack_s16_be(const unsigned char *);
-long  unpack_s32_be(const unsigned char *);
 #if PACK_HAVE_64BIT
 long long unpack_s64_be(const unsigned char *);
-#endif
-
-short unpack_s16_le(const unsigned char *);
-long  unpack_s32_le(const unsigned char *);
-#if PACK_HAVE_64BIT
 long long unpack_s64_le(const unsigned char *);
+unsigned long long unpack_64_be(const unsigned char *);
+unsigned long long unpack_64_le(const unsigned char *);
+void pack_64_be(unsigned char *, unsigned long long);
+void pack_64_le(unsigned char *, unsigned long long);
 #endif
 
 #endif