1
0
Fork 0
mirror of https://git.tukaani.org/xz.git synced 2024-04-04 12:36:23 +02:00

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.
This commit is contained in:
Lasse Collin 2008-01-06 16:27:41 +02:00
parent a71864f77d
commit 4e7e54c4c5
13 changed files with 106 additions and 35 deletions

View file

@ -392,10 +392,21 @@ AC_CHECK_HEADERS([assert.h errno.h byteswap.h sys/param.h sys/sysctl.h],
# Checks for typedefs, structures, and compiler characteristics. # Checks for typedefs, structures, and compiler characteristics.
############################################################################### ###############################################################################
AC_HEADER_STDBOOL
AC_C_INLINE AC_C_INLINE
AC_C_RESTRICT AC_C_RESTRICT
AC_HEADER_STDBOOL
AC_TYPE_UINT8_T
AC_TYPE_INT32_T
AC_TYPE_UINT32_T
AC_TYPE_INT64_T
AC_TYPE_UINT64_T
AC_TYPE_UINTPTR_T
AC_CHECK_SIZEOF([unsigned long])
AC_CHECK_SIZEOF([size_t])
# The command line tool can copy high resolution timestamps if such # The command line tool can copy high resolution timestamps if such
# information is availabe in struct stat. Otherwise one second accuracy # information is availabe in struct stat. Otherwise one second accuracy
# is used. Most systems seem to have st_xtim but BSDs have st_xtimespec. # is used. Most systems seem to have st_xtim but BSDs have st_xtimespec.

View file

@ -5,8 +5,14 @@ Introduction to liblzma
Writing applications to work with liblzma Writing applications to work with liblzma
liblzma API is split in several subheaders to improve readability and liblzma API is split in several subheaders to improve readability and
maintainance. The subheaders must not be #included directly; simply maintainance. The subheaders must not be #included directly. lzma.h
use `#include <lzma.h>' instead. requires that certain integer types and macros are available when
the header is #included. On systems that have inttypes.h that conforms
to C99, the following will work:
#include <sys/types.h>
#include <inttypes.h>
#include <lzma.h>
Those who have used zlib should find liblzma's API easy to use. Those who have used zlib should find liblzma's API easy to use.
To developers who haven't used zlib before, I recommend learning To developers who haven't used zlib before, I recommend learning

View file

@ -31,7 +31,62 @@
# include <config.h> # include <config.h>
#endif #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> #include <stdlib.h>
@ -70,6 +125,8 @@ typedef unsigned char _Bool;
# include <memory.h> # include <memory.h>
#endif #endif
#include "lzma.h"
//////////// ////////////
// Macros // // Macros //

View file

@ -17,25 +17,37 @@
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details. * Lesser General Public License for more details.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* Before #including this file, you must make the following types available:
* - size_t
* - uint8_t
* - int32_t
* - uint32_t
* - int64_t
* - uint64_t
*
* Before #including this file, you must make the following macros available:
* - UINT32_C(n)
* - UINT64_C(n)
* - UINT32_MAX
* - UINT64_MAX
*
* Easiest way to achieve the above is to #include sys/types.h and inttypes.h
* before #including lzma.h. However, some pre-C99 libc headers don't provide
* all the required types in inttypes.h (that file may even be missing).
* Portable applications need to provide these types themselves. This way
* liblzma API can use the standard types instead of defining its own
* (e.g. lzma_uint32).
*
* Note that the API still has lzma_bool, because using stdbool.h would
* break C89 and C++ programs on many systems.
*/ */
#ifndef LZMA_H #ifndef LZMA_H
#define LZMA_H #define LZMA_H
/********************
* External headers *
********************/
/* size_t */
#include <sys/types.h>
/* NULL */
#include <stddef.h>
/* uint8_t, uint32_t, uint64_t, UINT32_C, UINT64_C, UINT64_MAX. */
#include <inttypes.h>
/****************** /******************
* GCC extensions * * GCC extensions *
******************/ ******************/

View file

@ -11,9 +11,7 @@
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H #include "sysdefs.h"
# include <config.h>
#endif
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
# include "crc32_table_be.h" # include "crc32_table_be.h"

View file

@ -1,7 +1,5 @@
/* This file has been automatically generated by crc32_tablegen.c. */ /* This file has been automatically generated by crc32_tablegen.c. */
#include <inttypes.h>
const uint32_t lzma_crc32_table[8][256] = { const uint32_t lzma_crc32_table[8][256] = {
{ {
0x00000000, 0x96300777, 0x2C610EEE, 0xBA510999, 0x00000000, 0x96300777, 0x2C610EEE, 0xBA510999,

View file

@ -1,7 +1,5 @@
/* This file has been automatically generated by crc32_tablegen.c. */ /* This file has been automatically generated by crc32_tablegen.c. */
#include <inttypes.h>
const uint32_t lzma_crc32_table[8][256] = { const uint32_t lzma_crc32_table[8][256] = {
{ {
0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA,

View file

@ -31,7 +31,6 @@ main()
printf("/* This file has been automatically generated by " printf("/* This file has been automatically generated by "
"crc32_tablegen.c. */\n\n" "crc32_tablegen.c. */\n\n"
"#include <inttypes.h>\n\n"
"const uint32_t lzma_crc32_table[8][256] = {\n\t{"); "const uint32_t lzma_crc32_table[8][256] = {\n\t{");
for (size_t s = 0; s < 8; ++s) { for (size_t s = 0; s < 8; ++s) {

View file

@ -11,9 +11,7 @@
// //
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////
#ifdef HAVE_CONFIG_H #include "sysdefs.h"
# include <config.h>
#endif
#ifdef WORDS_BIGENDIAN #ifdef WORDS_BIGENDIAN
# include "crc64_table_be.h" # include "crc64_table_be.h"

View file

@ -1,7 +1,5 @@
/* This file has been automatically generated by crc64_tablegen.c. */ /* This file has been automatically generated by crc64_tablegen.c. */
#include <inttypes.h>
const uint64_t lzma_crc64_table[4][256] = { const uint64_t lzma_crc64_table[4][256] = {
{ {
UINT64_C(0x0000000000000000), UINT64_C(0x6F5FA703BE4C2EB3), UINT64_C(0x0000000000000000), UINT64_C(0x6F5FA703BE4C2EB3),

View file

@ -1,7 +1,5 @@
/* This file has been automatically generated by crc64_tablegen.c. */ /* This file has been automatically generated by crc64_tablegen.c. */
#include <inttypes.h>
const uint64_t lzma_crc64_table[4][256] = { const uint64_t lzma_crc64_table[4][256] = {
{ {
UINT64_C(0x0000000000000000), UINT64_C(0xB32E4CBE03A75F6F), UINT64_C(0x0000000000000000), UINT64_C(0xB32E4CBE03A75F6F),

View file

@ -31,7 +31,6 @@ main()
printf("/* This file has been automatically generated by " printf("/* This file has been automatically generated by "
"crc64_tablegen.c. */\n\n" "crc64_tablegen.c. */\n\n"
"#include <inttypes.h>\n\n"
"const uint64_t lzma_crc64_table[4][256] = {\n\t{"); "const uint64_t lzma_crc64_table[4][256] = {\n\t{");
for (size_t s = 0; s < 4; ++s) { for (size_t s = 0; s < 4; ++s) {

View file

@ -29,7 +29,6 @@ extern int errno;
#endif #endif
#include <sys/stat.h> #include <sys/stat.h>
#include <limits.h>
#include <signal.h> #include <signal.h>
#include <pthread.h> #include <pthread.h>
#include <locale.h> #include <locale.h>