jpayne@69: /* SPDX-License-Identifier: 0BSD */
jpayne@69:
jpayne@69: /**
jpayne@69: * \file api/lzma.h
jpayne@69: * \brief The public API of liblzma data compression library
jpayne@69: * \mainpage
jpayne@69: *
jpayne@69: * liblzma is a general-purpose data compression library with a zlib-like API.
jpayne@69: * The native file format is .xz, but also the old .lzma format and raw (no
jpayne@69: * headers) streams are supported. Multiple compression algorithms (filters)
jpayne@69: * are supported. Currently LZMA2 is the primary filter.
jpayne@69: *
jpayne@69: * liblzma is part of XZ Utils . XZ Utils
jpayne@69: * includes a gzip-like command line tool named xz and some other tools.
jpayne@69: * XZ Utils is developed and maintained by Lasse Collin.
jpayne@69: *
jpayne@69: * Major parts of liblzma are based on code written by Igor Pavlov,
jpayne@69: * specifically the LZMA SDK .
jpayne@69: *
jpayne@69: * The SHA-256 implementation in liblzma is based on code written by
jpayne@69: * Wei Dai in Crypto++ Library .
jpayne@69: *
jpayne@69: * liblzma is distributed under the BSD Zero Clause License (0BSD).
jpayne@69: */
jpayne@69:
jpayne@69: /*
jpayne@69: * Author: Lasse Collin
jpayne@69: */
jpayne@69:
jpayne@69: #ifndef LZMA_H
jpayne@69: #define LZMA_H
jpayne@69:
jpayne@69: /*****************************
jpayne@69: * Required standard headers *
jpayne@69: *****************************/
jpayne@69:
jpayne@69: /*
jpayne@69: * liblzma API headers need some standard types and macros. To allow
jpayne@69: * including lzma.h without requiring the application to include other
jpayne@69: * headers first, lzma.h includes the required standard headers unless
jpayne@69: * they already seem to be included already or if LZMA_MANUAL_HEADERS
jpayne@69: * has been defined.
jpayne@69: *
jpayne@69: * Here's what types and macros are needed and from which headers:
jpayne@69: * - stddef.h: size_t, NULL
jpayne@69: * - stdint.h: uint8_t, uint32_t, uint64_t, UINT32_C(n), uint64_C(n),
jpayne@69: * UINT32_MAX, UINT64_MAX
jpayne@69: *
jpayne@69: * However, inttypes.h is a little more portable than stdint.h, although
jpayne@69: * inttypes.h declares some unneeded things compared to plain stdint.h.
jpayne@69: *
jpayne@69: * The hacks below aren't perfect, specifically they assume that inttypes.h
jpayne@69: * exists and that it typedefs at least uint8_t, uint32_t, and uint64_t,
jpayne@69: * and that, in case of incomplete inttypes.h, unsigned int is 32-bit.
jpayne@69: * If the application already takes care of setting up all the types and
jpayne@69: * macros properly (for example by using gnulib's stdint.h or inttypes.h),
jpayne@69: * we try to detect that the macros are already defined and don't include
jpayne@69: * inttypes.h here again. However, you may define LZMA_MANUAL_HEADERS to
jpayne@69: * force this file to never include any system headers.
jpayne@69: *
jpayne@69: * Some could argue that liblzma API should provide all the required types,
jpayne@69: * for example lzma_uint64, LZMA_UINT64_C(n), and LZMA_UINT64_MAX. This was
jpayne@69: * seen as an unnecessary mess, since most systems already provide all the
jpayne@69: * necessary types and macros in the standard headers.
jpayne@69: *
jpayne@69: * Note that liblzma API still has lzma_bool, because using stdbool.h would
jpayne@69: * break C89 and C++ programs on many systems. sizeof(bool) in C99 isn't
jpayne@69: * necessarily the same as sizeof(bool) in C++.
jpayne@69: */
jpayne@69:
jpayne@69: #ifndef LZMA_MANUAL_HEADERS
jpayne@69: /*
jpayne@69: * I suppose this works portably also in C++. Note that in C++,
jpayne@69: * we need to get size_t into the global namespace.
jpayne@69: */
jpayne@69: # include
jpayne@69:
jpayne@69: /*
jpayne@69: * Skip inttypes.h if we already have all the required macros. If we
jpayne@69: * have the macros, we assume that we have the matching typedefs too.
jpayne@69: */
jpayne@69: # if !defined(UINT32_C) || !defined(UINT64_C) \
jpayne@69: || !defined(UINT32_MAX) || !defined(UINT64_MAX)
jpayne@69: /*
jpayne@69: * MSVC versions older than 2013 have no C99 support, and
jpayne@69: * thus they cannot be used to compile liblzma. Using an
jpayne@69: * existing liblzma.dll with old MSVC can work though(*),
jpayne@69: * but we need to define the required standard integer
jpayne@69: * types here in a MSVC-specific way.
jpayne@69: *
jpayne@69: * (*) If you do this, the existing liblzma.dll probably uses
jpayne@69: * a different runtime library than your MSVC-built
jpayne@69: * application. Mixing runtimes is generally bad, but
jpayne@69: * in this case it should work as long as you avoid
jpayne@69: * the few rarely-needed liblzma functions that allocate
jpayne@69: * memory and expect the caller to free it using free().
jpayne@69: */
jpayne@69: # if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1800
jpayne@69: typedef unsigned __int8 uint8_t;
jpayne@69: typedef unsigned __int32 uint32_t;
jpayne@69: typedef unsigned __int64 uint64_t;
jpayne@69: # else
jpayne@69: /* Use the standard inttypes.h. */
jpayne@69: # ifdef __cplusplus
jpayne@69: /*
jpayne@69: * C99 sections 7.18.2 and 7.18.4 specify
jpayne@69: * that C++ implementations define the limit
jpayne@69: * and constant macros only if specifically
jpayne@69: * requested. Note that if you want the
jpayne@69: * format macros (PRIu64 etc.) too, you need
jpayne@69: * to define __STDC_FORMAT_MACROS before
jpayne@69: * including lzma.h, since re-including
jpayne@69: * inttypes.h with __STDC_FORMAT_MACROS
jpayne@69: * defined doesn't necessarily work.
jpayne@69: */
jpayne@69: # ifndef __STDC_LIMIT_MACROS
jpayne@69: # define __STDC_LIMIT_MACROS 1
jpayne@69: # endif
jpayne@69: # ifndef __STDC_CONSTANT_MACROS
jpayne@69: # define __STDC_CONSTANT_MACROS 1
jpayne@69: # endif
jpayne@69: # endif
jpayne@69:
jpayne@69: # include
jpayne@69: # endif
jpayne@69:
jpayne@69: /*
jpayne@69: * Some old systems have only the typedefs in inttypes.h, and
jpayne@69: * lack all the macros. For those systems, we need a few more
jpayne@69: * hacks. We assume that unsigned int is 32-bit and unsigned
jpayne@69: * long is either 32-bit or 64-bit. If these hacks aren't
jpayne@69: * enough, the application has to setup the types manually
jpayne@69: * before including lzma.h.
jpayne@69: */
jpayne@69: # ifndef UINT32_C
jpayne@69: # if defined(_WIN32) && defined(_MSC_VER)
jpayne@69: # define UINT32_C(n) n ## UI32
jpayne@69: # else
jpayne@69: # define UINT32_C(n) n ## U
jpayne@69: # endif
jpayne@69: # endif
jpayne@69:
jpayne@69: # ifndef UINT64_C
jpayne@69: # if defined(_WIN32) && defined(_MSC_VER)
jpayne@69: # define UINT64_C(n) n ## UI64
jpayne@69: # else
jpayne@69: /* Get ULONG_MAX. */
jpayne@69: # include
jpayne@69: # if ULONG_MAX == 4294967295UL
jpayne@69: # define UINT64_C(n) n ## ULL
jpayne@69: # else
jpayne@69: # define UINT64_C(n) n ## UL
jpayne@69: # endif
jpayne@69: # endif
jpayne@69: # endif
jpayne@69:
jpayne@69: # ifndef UINT32_MAX
jpayne@69: # define UINT32_MAX (UINT32_C(4294967295))
jpayne@69: # endif
jpayne@69:
jpayne@69: # ifndef UINT64_MAX
jpayne@69: # define UINT64_MAX (UINT64_C(18446744073709551615))
jpayne@69: # endif
jpayne@69: # endif
jpayne@69: #endif /* ifdef LZMA_MANUAL_HEADERS */
jpayne@69:
jpayne@69:
jpayne@69: /******************
jpayne@69: * LZMA_API macro *
jpayne@69: ******************/
jpayne@69:
jpayne@69: /*
jpayne@69: * Some systems require that the functions and function pointers are
jpayne@69: * declared specially in the headers. LZMA_API_IMPORT is for importing
jpayne@69: * symbols and LZMA_API_CALL is to specify the calling convention.
jpayne@69: *
jpayne@69: * By default it is assumed that the application will link dynamically
jpayne@69: * against liblzma. #define LZMA_API_STATIC in your application if you
jpayne@69: * want to link against static liblzma. If you don't care about portability
jpayne@69: * to operating systems like Windows, or at least don't care about linking
jpayne@69: * against static liblzma on them, don't worry about LZMA_API_STATIC. That
jpayne@69: * is, most developers will never need to use LZMA_API_STATIC.
jpayne@69: *
jpayne@69: * The GCC variants are a special case on Windows (Cygwin and MinGW-w64).
jpayne@69: * We rely on GCC doing the right thing with its auto-import feature,
jpayne@69: * and thus don't use __declspec(dllimport). This way developers don't
jpayne@69: * need to worry about LZMA_API_STATIC. Also the calling convention is
jpayne@69: * omitted on Cygwin but not on MinGW-w64.
jpayne@69: */
jpayne@69: #ifndef LZMA_API_IMPORT
jpayne@69: # if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__GNUC__)
jpayne@69: # define LZMA_API_IMPORT __declspec(dllimport)
jpayne@69: # else
jpayne@69: # define LZMA_API_IMPORT
jpayne@69: # endif
jpayne@69: #endif
jpayne@69:
jpayne@69: #ifndef LZMA_API_CALL
jpayne@69: # if defined(_WIN32) && !defined(__CYGWIN__)
jpayne@69: # define LZMA_API_CALL __cdecl
jpayne@69: # else
jpayne@69: # define LZMA_API_CALL
jpayne@69: # endif
jpayne@69: #endif
jpayne@69:
jpayne@69: #ifndef LZMA_API
jpayne@69: # define LZMA_API(type) LZMA_API_IMPORT type LZMA_API_CALL
jpayne@69: #endif
jpayne@69:
jpayne@69:
jpayne@69: /***********
jpayne@69: * nothrow *
jpayne@69: ***********/
jpayne@69:
jpayne@69: /*
jpayne@69: * None of the functions in liblzma may throw an exception. Even
jpayne@69: * the functions that use callback functions won't throw exceptions,
jpayne@69: * because liblzma would break if a callback function threw an exception.
jpayne@69: */
jpayne@69: #ifndef lzma_nothrow
jpayne@69: # if defined(__cplusplus)
jpayne@69: # if __cplusplus >= 201103L || (defined(_MSVC_LANG) \
jpayne@69: && _MSVC_LANG >= 201103L)
jpayne@69: # define lzma_nothrow noexcept
jpayne@69: # else
jpayne@69: # define lzma_nothrow throw()
jpayne@69: # endif
jpayne@69: # elif defined(__GNUC__) && (__GNUC__ > 3 \
jpayne@69: || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))
jpayne@69: # define lzma_nothrow __attribute__((__nothrow__))
jpayne@69: # else
jpayne@69: # define lzma_nothrow
jpayne@69: # endif
jpayne@69: #endif
jpayne@69:
jpayne@69:
jpayne@69: /********************
jpayne@69: * GNU C extensions *
jpayne@69: ********************/
jpayne@69:
jpayne@69: /*
jpayne@69: * GNU C extensions are used conditionally in the public API. It doesn't
jpayne@69: * break anything if these are sometimes enabled and sometimes not, only
jpayne@69: * affects warnings and optimizations.
jpayne@69: */
jpayne@69: #if defined(__GNUC__) && __GNUC__ >= 3
jpayne@69: # ifndef lzma_attribute
jpayne@69: # define lzma_attribute(attr) __attribute__(attr)
jpayne@69: # endif
jpayne@69:
jpayne@69: /* warn_unused_result was added in GCC 3.4. */
jpayne@69: # ifndef lzma_attr_warn_unused_result
jpayne@69: # if __GNUC__ == 3 && __GNUC_MINOR__ < 4
jpayne@69: # define lzma_attr_warn_unused_result
jpayne@69: # endif
jpayne@69: # endif
jpayne@69:
jpayne@69: #else
jpayne@69: # ifndef lzma_attribute
jpayne@69: # define lzma_attribute(attr)
jpayne@69: # endif
jpayne@69: #endif
jpayne@69:
jpayne@69:
jpayne@69: #ifndef lzma_attr_pure
jpayne@69: # define lzma_attr_pure lzma_attribute((__pure__))
jpayne@69: #endif
jpayne@69:
jpayne@69: #ifndef lzma_attr_const
jpayne@69: # define lzma_attr_const lzma_attribute((__const__))
jpayne@69: #endif
jpayne@69:
jpayne@69: #ifndef lzma_attr_warn_unused_result
jpayne@69: # define lzma_attr_warn_unused_result \
jpayne@69: lzma_attribute((__warn_unused_result__))
jpayne@69: #endif
jpayne@69:
jpayne@69:
jpayne@69: /**************
jpayne@69: * Subheaders *
jpayne@69: **************/
jpayne@69:
jpayne@69: #ifdef __cplusplus
jpayne@69: extern "C" {
jpayne@69: #endif
jpayne@69:
jpayne@69: /*
jpayne@69: * Subheaders check that this is defined. It is to prevent including
jpayne@69: * them directly from applications.
jpayne@69: */
jpayne@69: #define LZMA_H_INTERNAL 1
jpayne@69:
jpayne@69: /* Basic features */
jpayne@69: #include "lzma/version.h"
jpayne@69: #include "lzma/base.h"
jpayne@69: #include "lzma/vli.h"
jpayne@69: #include "lzma/check.h"
jpayne@69:
jpayne@69: /* Filters */
jpayne@69: #include "lzma/filter.h"
jpayne@69: #include "lzma/bcj.h"
jpayne@69: #include "lzma/delta.h"
jpayne@69: #include "lzma/lzma12.h"
jpayne@69:
jpayne@69: /* Container formats */
jpayne@69: #include "lzma/container.h"
jpayne@69:
jpayne@69: /* Advanced features */
jpayne@69: #include "lzma/stream_flags.h"
jpayne@69: #include "lzma/block.h"
jpayne@69: #include "lzma/index.h"
jpayne@69: #include "lzma/index_hash.h"
jpayne@69:
jpayne@69: /* Hardware information */
jpayne@69: #include "lzma/hardware.h"
jpayne@69:
jpayne@69: /*
jpayne@69: * All subheaders included. Undefine LZMA_H_INTERNAL to prevent applications
jpayne@69: * re-including the subheaders.
jpayne@69: */
jpayne@69: #undef LZMA_H_INTERNAL
jpayne@69:
jpayne@69: #ifdef __cplusplus
jpayne@69: }
jpayne@69: #endif
jpayne@69:
jpayne@69: #endif /* ifndef LZMA_H */