diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2008-01-06 16:27:41 +0200 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2008-01-06 16:27:41 +0200 |
commit | 4e7e54c4c522ab2f6a7abb92cefc4f707e9568fb (patch) | |
tree | 852cde1e5bef3e46c5415884e283ef874f8eed73 /src/common | |
parent | Fix typo in comment (INT64_MAX -> UINT64_MAX). (diff) | |
download | xz-4e7e54c4c522ab2f6a7abb92cefc4f707e9568fb.tar.xz |
Introduced compatibility with systems that have pre-C99
or no inttypes.h. This is useful when the compiler has
good enough support for C99, but libc headers don't.
Changed liblzma API so that sys/types.h and inttypes.h
have to be #included before #including lzma.h. On systems
that don't have C99 inttypes.h, it's the problem of the
applications to provide the required types and macros
before #including lzma.h.
If lzma.h defined the missing types and macros, it could
conflict with third-party applications whose configure
has detected that the types are missing and defined them
in config.h already. An alternative would have been
introducing lzma_uint32 and similar types, but that would
just be an extra pain on modern systems.
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/sysdefs.h | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/src/common/sysdefs.h b/src/common/sysdefs.h index b4ba8a56..7b69504c 100644 --- a/src/common/sysdefs.h +++ b/src/common/sysdefs.h @@ -31,7 +31,62 @@ # include <config.h> #endif -#include "lzma.h" +#include <sys/types.h> + +#ifdef HAVE_INTTYPES_H +# include <inttypes.h> +#endif + +#ifdef HAVE_LIMITS_H +# include <limits.h> +#endif + +// Be more compatible with systems that have non-conforming inttypes.h. +// We assume that int is 32-bit and that long is either 32-bit or 64-bit. +// Full Autoconf test could be more correct, but this should work well enough. +#ifndef UINT32_C +# define UINT32_C(n) n ## U +#endif +#ifndef UINT32_MAX +# define UINT32_MAX UINT32_C(4294967295) +#endif +#ifndef PRIu32 +# define PRIu32 "u" +#endif +#ifndef PRIX32 +# define PRIX32 "X" +#endif +#if SIZEOF_UNSIGNED_LONG == 4 +# ifndef UINT64_C +# define UINT64_C(n) n ## ULL +# endif +# ifndef PRIu64 +# define PRIu64 "llu" +# endif +# ifndef PRIX64 +# define PRIX64 "llX" +# endif +#else +# ifndef UINT64_C +# define UINT64_C(n) n ## UL +# endif +# ifndef PRIu64 +# define PRIu64 "lu" +# endif +# ifndef PRIX64 +# define PRIX64 "lX" +# endif +#endif +#ifndef UINT64_MAX +# define UINT64_MAX UINT64_C(18446744073709551615) +#endif +#ifndef SIZE_MAX +# if SIZEOF_SIZE_T == 4 +# define SIZE_MAX UINT32_MAX +# else +# define SIZE_MAX UINT64_MAX +# endif +#endif #include <stdlib.h> @@ -70,6 +125,8 @@ typedef unsigned char _Bool; # include <memory.h> #endif +#include "lzma.h" + //////////// // Macros // |