From c21a2dbaee36c49e45a9d5872aca8caf46b3bbd7 Mon Sep 17 00:00:00 2001 From: Josef 'Jeff' Sipek Date: Thu, 5 Jul 2018 10:48:49 -0400 Subject: [PATCH] lib: Make sure exactly one of _ILP32 and _LP64 is defined at all times These defines are very common, but not universal. For example, clang on illumos and FreeBSD always defines one of them, while 32-bit Ubuntu 16.04 doesn't define either. --- src/lib/compat.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/lib/compat.h b/src/lib/compat.h index dbda02f809..ce3127ddb4 100644 --- a/src/lib/compat.h +++ b/src/lib/compat.h @@ -1,6 +1,22 @@ #ifndef COMPAT_H #define COMPAT_H +/* _ILP32 and _LP64 are common but not universal, make sure that exactly one + of them is defined. */ +#if !defined(_ILP32) && \ + (SIZEOF_INT == 4) && (SIZEOF_LONG == 4) && (SIZEOF_VOID_P == 4) +# define _ILP32 +#endif +#if !defined(_LP64) && \ + (SIZEOF_INT == 4) && (SIZEOF_LONG == 8) && (SIZEOF_VOID_P == 8) +# define _LP64 +#endif +#if defined(_ILP32) && defined(_LP64) +# error "Cannot have both _ILP32 and _LP64 defined" +#elif !defined(_ILP32) && !defined(_LP64) +# error "Must have one of _ILP32 and _LP64 defined" +#endif + /* well, this is obviously wrong since it assumes it's 64bit, but older GCCs don't define it and we really want it. */ #ifndef LLONG_MAX -- 2.47.3