/* SPDX-License-Identifier: 0BSD */12/**3* \file api/lzma.h4* \brief The public API of liblzma data compression library5* \mainpage6*7* liblzma is a general-purpose data compression library with a zlib-like API.8* The native file format is .xz, but also the old .lzma format and raw (no9* headers) streams are supported. Multiple compression algorithms (filters)10* are supported. Currently LZMA2 is the primary filter.11*12* liblzma is part of XZ Utils <https://tukaani.org/xz/>. XZ Utils13* includes a gzip-like command line tool named xz and some other tools.14* XZ Utils is developed and maintained by Lasse Collin.15*16* Major parts of liblzma are based on code written by Igor Pavlov,17* specifically the LZMA SDK <https://7-zip.org/sdk.html>.18*19* The SHA-256 implementation in liblzma is based on code written by20* Wei Dai in Crypto++ Library <https://www.cryptopp.com/>.21*22* liblzma is distributed under the BSD Zero Clause License (0BSD).23*/2425/*26* Author: Lasse Collin27*/2829#ifndef LZMA_H30#define LZMA_H3132/*****************************33* Required standard headers *34*****************************/3536/*37* liblzma API headers need some standard types and macros. To allow38* including lzma.h without requiring the application to include other39* headers first, lzma.h includes the required standard headers unless40* they already seem to be included already or if LZMA_MANUAL_HEADERS41* has been defined.42*43* Here's what types and macros are needed and from which headers:44* - stddef.h: size_t, NULL45* - stdint.h: uint8_t, uint32_t, uint64_t, UINT32_C(n), uint64_C(n),46* UINT32_MAX, UINT64_MAX47*48* However, inttypes.h is a little more portable than stdint.h, although49* inttypes.h declares some unneeded things compared to plain stdint.h.50*51* The hacks below aren't perfect, specifically they assume that inttypes.h52* exists and that it typedefs at least uint8_t, uint32_t, and uint64_t,53* and that, in case of incomplete inttypes.h, unsigned int is 32-bit.54* If the application already takes care of setting up all the types and55* macros properly (for example by using gnulib's stdint.h or inttypes.h),56* we try to detect that the macros are already defined and don't include57* inttypes.h here again. However, you may define LZMA_MANUAL_HEADERS to58* force this file to never include any system headers.59*60* Some could argue that liblzma API should provide all the required types,61* for example lzma_uint64, LZMA_UINT64_C(n), and LZMA_UINT64_MAX. This was62* seen as an unnecessary mess, since most systems already provide all the63* necessary types and macros in the standard headers.64*65* Note that liblzma API still has lzma_bool, because using stdbool.h would66* break C89 and C++ programs on many systems. sizeof(bool) in C99 isn't67* necessarily the same as sizeof(bool) in C++.68*/6970#ifndef LZMA_MANUAL_HEADERS71/*72* I suppose this works portably also in C++. Note that in C++,73* we need to get size_t into the global namespace.74*/75# include <stddef.h>7677/*78* Skip inttypes.h if we already have all the required macros. If we79* have the macros, we assume that we have the matching typedefs too.80*/81# if !defined(UINT32_C) || !defined(UINT64_C) \82|| !defined(UINT32_MAX) || !defined(UINT64_MAX)83/*84* MSVC versions older than 2013 have no C99 support, and85* thus they cannot be used to compile liblzma. Using an86* existing liblzma.dll with old MSVC can work though(*),87* but we need to define the required standard integer88* types here in a MSVC-specific way.89*90* (*) If you do this, the existing liblzma.dll probably uses91* a different runtime library than your MSVC-built92* application. Mixing runtimes is generally bad, but93* in this case it should work as long as you avoid94* the few rarely-needed liblzma functions that allocate95* memory and expect the caller to free it using free().96*/97# if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 180098typedef unsigned __int8 uint8_t;99typedef unsigned __int32 uint32_t;100typedef unsigned __int64 uint64_t;101# else102/* Use the standard inttypes.h. */103# ifdef __cplusplus104/*105* C99 sections 7.18.2 and 7.18.4 specify106* that C++ implementations define the limit107* and constant macros only if specifically108* requested. Note that if you want the109* format macros (PRIu64 etc.) too, you need110* to define __STDC_FORMAT_MACROS before111* including lzma.h, since re-including112* inttypes.h with __STDC_FORMAT_MACROS113* defined doesn't necessarily work.114*/115# ifndef __STDC_LIMIT_MACROS116# define __STDC_LIMIT_MACROS 1117# endif118# ifndef __STDC_CONSTANT_MACROS119# define __STDC_CONSTANT_MACROS 1120# endif121# endif122123# include <inttypes.h>124# endif125126/*127* Some old systems have only the typedefs in inttypes.h, and128* lack all the macros. For those systems, we need a few more129* hacks. We assume that unsigned int is 32-bit and unsigned130* long is either 32-bit or 64-bit. If these hacks aren't131* enough, the application has to setup the types manually132* before including lzma.h.133*/134# ifndef UINT32_C135# if defined(_WIN32) && defined(_MSC_VER)136# define UINT32_C(n) n ## UI32137# else138# define UINT32_C(n) n ## U139# endif140# endif141142# ifndef UINT64_C143# if defined(_WIN32) && defined(_MSC_VER)144# define UINT64_C(n) n ## UI64145# else146/* Get ULONG_MAX. */147# include <limits.h>148# if ULONG_MAX == 4294967295UL149# define UINT64_C(n) n ## ULL150# else151# define UINT64_C(n) n ## UL152# endif153# endif154# endif155156# ifndef UINT32_MAX157# define UINT32_MAX (UINT32_C(4294967295))158# endif159160# ifndef UINT64_MAX161# define UINT64_MAX (UINT64_C(18446744073709551615))162# endif163# endif164#endif /* ifdef LZMA_MANUAL_HEADERS */165166167/******************168* LZMA_API macro *169******************/170171/*172* Some systems require that the functions and function pointers are173* declared specially in the headers. LZMA_API_IMPORT is for importing174* symbols and LZMA_API_CALL is to specify the calling convention.175*176* By default it is assumed that the application will link dynamically177* against liblzma. #define LZMA_API_STATIC in your application if you178* want to link against static liblzma. If you don't care about portability179* to operating systems like Windows, or at least don't care about linking180* against static liblzma on them, don't worry about LZMA_API_STATIC. That181* is, most developers will never need to use LZMA_API_STATIC.182*183* The GCC variants are a special case on Windows (Cygwin and MinGW-w64).184* We rely on GCC doing the right thing with its auto-import feature,185* and thus don't use __declspec(dllimport). This way developers don't186* need to worry about LZMA_API_STATIC. Also the calling convention is187* omitted on Cygwin but not on MinGW-w64.188*/189#ifndef LZMA_API_IMPORT190# if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__GNUC__)191# define LZMA_API_IMPORT __declspec(dllimport)192# else193# define LZMA_API_IMPORT194# endif195#endif196197#ifndef LZMA_API_CALL198# if defined(_WIN32) && !defined(__CYGWIN__)199# define LZMA_API_CALL __cdecl200# else201# define LZMA_API_CALL202# endif203#endif204205#ifndef LZMA_API206# define LZMA_API(type) LZMA_API_IMPORT type LZMA_API_CALL207#endif208209210/***********211* nothrow *212***********/213214/*215* None of the functions in liblzma may throw an exception. Even216* the functions that use callback functions won't throw exceptions,217* because liblzma would break if a callback function threw an exception.218*/219#ifndef lzma_nothrow220# if defined(__cplusplus)221# if __cplusplus >= 201103L || (defined(_MSVC_LANG) \222&& _MSVC_LANG >= 201103L)223# define lzma_nothrow noexcept224# else225# define lzma_nothrow throw()226# endif227# elif defined(__GNUC__) && (__GNUC__ > 3 \228|| (__GNUC__ == 3 && __GNUC_MINOR__ >= 3))229# define lzma_nothrow __attribute__((__nothrow__))230# else231# define lzma_nothrow232# endif233#endif234235236/********************237* GNU C extensions *238********************/239240/*241* GNU C extensions are used conditionally in the public API. It doesn't242* break anything if these are sometimes enabled and sometimes not, only243* affects warnings and optimizations.244*/245#if defined(__GNUC__) && __GNUC__ >= 3246# ifndef lzma_attribute247# define lzma_attribute(attr) __attribute__(attr)248# endif249250/* warn_unused_result was added in GCC 3.4. */251# ifndef lzma_attr_warn_unused_result252# if __GNUC__ == 3 && __GNUC_MINOR__ < 4253# define lzma_attr_warn_unused_result254# endif255# endif256257#else258# ifndef lzma_attribute259# define lzma_attribute(attr)260# endif261#endif262263264#ifndef lzma_attr_pure265# define lzma_attr_pure lzma_attribute((__pure__))266#endif267268#ifndef lzma_attr_const269# define lzma_attr_const lzma_attribute((__const__))270#endif271272#ifndef lzma_attr_warn_unused_result273# define lzma_attr_warn_unused_result \274lzma_attribute((__warn_unused_result__))275#endif276277278/**************279* Subheaders *280**************/281282#ifdef __cplusplus283extern "C" {284#endif285286/*287* Subheaders check that this is defined. It is to prevent including288* them directly from applications.289*/290#define LZMA_H_INTERNAL 1291292/* Basic features */293#include "lzma/version.h"294#include "lzma/base.h"295#include "lzma/vli.h"296#include "lzma/check.h"297298/* Filters */299#include "lzma/filter.h"300#include "lzma/bcj.h"301#include "lzma/delta.h"302#include "lzma/lzma12.h"303304/* Container formats */305#include "lzma/container.h"306307/* Advanced features */308#include "lzma/stream_flags.h"309#include "lzma/block.h"310#include "lzma/index.h"311#include "lzma/index_hash.h"312313/* Hardware information */314#include "lzma/hardware.h"315316/*317* All subheaders included. Undefine LZMA_H_INTERNAL to prevent applications318* re-including the subheaders.319*/320#undef LZMA_H_INTERNAL321322#ifdef __cplusplus323}324#endif325326#endif /* ifndef LZMA_H */327328329