# HG changeset patch # User Matti Hamalainen # Date 1420654887 -7200 # Node ID 9bc7f60f3013cdc7f721a2a67ee69ab3a68e69ca # Parent 6a0e9980b76b0f06e85d869ff86d383b7cc4407e More portability stuff. :| diff -r 6a0e9980b76b -r 9bc7f60f3013 th_network.c --- a/th_network.c Wed Jan 07 17:04:31 2015 +0200 +++ b/th_network.c Wed Jan 07 20:21:27 2015 +0200 @@ -943,8 +943,8 @@ fprintf(f, "\n--------------------------------------------------------------\n" - "err=%d, status=%d, got_bytes=%zd, total_bytes=%zd\n" - "buf=0x%p, in_ptr=0x%04zx, ptr=0x%04zx\n", + "err=%d, status=%d, got_bytes=%" TH_PRIu_SIZE_T ", total_bytes=%" TH_PRIu_SIZE_T "\n" + "buf=0x%p, in_ptr=0x%04" TH_PRIx_SIZE_T ", ptr=0x%04" TH_PRIx_SIZE_T "\n", conn->err, conn->status, conn->base.got_bytes, conn->base.total_bytes, conn->base.buf, conn->base.in_ptr - conn->base.buf, conn->base.ptr - conn->base.buf); diff -r 6a0e9980b76b -r 9bc7f60f3013 th_types.h --- a/th_types.h Wed Jan 07 17:04:31 2015 +0200 +++ b/th_types.h Wed Jan 07 20:21:27 2015 +0200 @@ -11,18 +11,67 @@ #ifndef _TH_TYPES_H #define _TH_TYPES_H +// Check for standard headers #ifdef HAVE_STDINT_H -#include -#ifndef HAVE_INT_TYPES -#define HAVE_INT_TYPES 1 -#endif +# include +# ifndef HAVE_INT_TYPES +# define HAVE_INT_TYPES 1 +# endif +// Check for arch bitness +# if UINTPTR_MAX == 0xffffffff +# define TH_ARCH 32 +# elif UINTPTR_MAX == 0xffffffffffffffff +# define TH_ARCH 64 +# endif #endif #ifdef HAVE_SYS_TYPES_H -#include -#ifndef HAVE_INT_TYPES -#define HAVE_INT_TYPES 1 +# include +# ifndef HAVE_INT_TYPES +# define HAVE_INT_TYPES 1 +# endif +#endif + +#if !defined(TH_ARCH) +# if defined(__LP64__) || defined(_LP64) +# define TH_ARCH 64 +# else +# define TH_ARCH 32 +# endif +#endif + + +#if !defined(TH_ARCH) && (defined(__WIN32) || defined(_WIN32)) +# define TH_ARCH 32 #endif + + +// Do we have a valid arch? +// If so, set some printf specifiers +#if TH_ARCH == 32 +# define TH_ARCH_32BIT 1 +# define TH_PRIu32 "u" +# define TH_PRId32 "d" +# define TH_PRIx32 "x" +# define TH_PRIu64 "llu" +# define TH_PRId64 "lld" +# define TH_PRIx64 "llx" +# define TH_PRIu_SIZE_T "u" +# define TH_PRId_SSIZE_T "d" +# define TH_PRIx_SIZE_T "x" +#elif TH_ARCH == 64 +# define TH_ARCH_64BIT 1 +# define TH_PRIu32 "u" +# define TH_PRId32 "d" +# define TH_PRIx32 "x" +# define TH_PRIu64 "lu" +# define TH_PRId64 "ld" +# define TH_PRIx64 "lx" +# define TH_PRIu_SIZE_T "lu" +# define TH_PRId_SSIZE_T "ld" +# define TH_PRIx_SIZE_T "lx" +#else +# error Could not determine architecture (32/64bit), please define TH_ARCH=32 or 64 #endif // Shorthand types