1207753Smm/** 2207753Smm * \file api/lzma.h 3207753Smm * \brief The public API of liblzma data compression library 4207753Smm * 5207753Smm * liblzma is a public domain general-purpose data compression library with 6207753Smm * a zlib-like API. The native file format is .xz, but also the old .lzma 7207753Smm * format and raw (no headers) streams are supported. Multiple compression 8207753Smm * algorithms (filters) are supported. Currently LZMA2 is the primary filter. 9207753Smm * 10207753Smm * liblzma is part of XZ Utils <http://tukaani.org/xz/>. XZ Utils includes 11207753Smm * a gzip-like command line tool named xz and some other tools. XZ Utils 12207753Smm * is developed and maintained by Lasse Collin. 13207753Smm * 14207753Smm * Major parts of liblzma are based on Igor Pavlov's public domain LZMA SDK 15207753Smm * <http://7-zip.org/sdk.html>. 16207753Smm * 17207753Smm * The SHA-256 implementation is based on the public domain code found from 18207753Smm * 7-Zip <http://7-zip.org/>, which has a modified version of the public 19207753Smm * domain SHA-256 code found from Crypto++ <http://www.cryptopp.com/>. 20207753Smm * The SHA-256 code in Crypto++ was written by Kevin Springle and Wei Dai. 21207753Smm */ 22207753Smm 23207753Smm/* 24207753Smm * Author: Lasse Collin 25207753Smm * 26207753Smm * This file has been put into the public domain. 27207753Smm * You can do whatever you want with this file. 28207753Smm */ 29207753Smm 30207753Smm#ifndef LZMA_H 31207753Smm#define LZMA_H 32207753Smm 33207753Smm/***************************** 34207753Smm * Required standard headers * 35207753Smm *****************************/ 36207753Smm 37207753Smm/* 38207753Smm * liblzma API headers need some standard types and macros. To allow 39207753Smm * including lzma.h without requiring the application to include other 40207753Smm * headers first, lzma.h includes the required standard headers unless 41207753Smm * they already seem to be included already or if LZMA_MANUAL_HEADERS 42207753Smm * has been defined. 43207753Smm * 44207753Smm * Here's what types and macros are needed and from which headers: 45207753Smm * - stddef.h: size_t, NULL 46207753Smm * - stdint.h: uint8_t, uint32_t, uint64_t, UINT32_C(n), uint64_C(n), 47207753Smm * UINT32_MAX, UINT64_MAX 48207753Smm * 49207753Smm * However, inttypes.h is a little more portable than stdint.h, although 50207753Smm * inttypes.h declares some unneeded things compared to plain stdint.h. 51207753Smm * 52207753Smm * The hacks below aren't perfect, specifically they assume that inttypes.h 53207753Smm * exists and that it typedefs at least uint8_t, uint32_t, and uint64_t, 54207753Smm * and that, in case of incomplete inttypes.h, unsigned int is 32-bit. 55207753Smm * If the application already takes care of setting up all the types and 56207753Smm * macros properly (for example by using gnulib's stdint.h or inttypes.h), 57207753Smm * we try to detect that the macros are already defined and don't include 58207753Smm * inttypes.h here again. However, you may define LZMA_MANUAL_HEADERS to 59207753Smm * force this file to never include any system headers. 60207753Smm * 61207753Smm * Some could argue that liblzma API should provide all the required types, 62207753Smm * for example lzma_uint64, LZMA_UINT64_C(n), and LZMA_UINT64_MAX. This was 63215187Smm * seen as an unnecessary mess, since most systems already provide all the 64215187Smm * necessary types and macros in the standard headers. 65207753Smm * 66207753Smm * Note that liblzma API still has lzma_bool, because using stdbool.h would 67207753Smm * break C89 and C++ programs on many systems. sizeof(bool) in C99 isn't 68207753Smm * necessarily the same as sizeof(bool) in C++. 69207753Smm */ 70207753Smm 71207753Smm#ifndef LZMA_MANUAL_HEADERS 72207753Smm /* 73207753Smm * I suppose this works portably also in C++. Note that in C++, 74207753Smm * we need to get size_t into the global namespace. 75207753Smm */ 76207753Smm# include <stddef.h> 77207753Smm 78207753Smm /* 79207753Smm * Skip inttypes.h if we already have all the required macros. If we 80207753Smm * have the macros, we assume that we have the matching typedefs too. 81207753Smm */ 82207753Smm# if !defined(UINT32_C) || !defined(UINT64_C) \ 83207753Smm || !defined(UINT32_MAX) || !defined(UINT64_MAX) 84207753Smm /* 85291125Sdelphij * MSVC versions older than 2013 have no C99 support, and 86291125Sdelphij * thus they cannot be used to compile liblzma. Using an 87291125Sdelphij * existing liblzma.dll with old MSVC can work though(*), 88291125Sdelphij * but we need to define the required standard integer 89291125Sdelphij * types here in a MSVC-specific way. 90291125Sdelphij * 91291125Sdelphij * (*) If you do this, the existing liblzma.dll probably uses 92291125Sdelphij * a different runtime library than your MSVC-built 93291125Sdelphij * application. Mixing runtimes is generally bad, but 94291125Sdelphij * in this case it should work as long as you avoid 95291125Sdelphij * the few rarely-needed liblzma functions that allocate 96291125Sdelphij * memory and expect the caller to free it using free(). 97207753Smm */ 98291125Sdelphij# if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER < 1800 99207753Smm typedef unsigned __int8 uint8_t; 100207753Smm typedef unsigned __int32 uint32_t; 101207753Smm typedef unsigned __int64 uint64_t; 102207753Smm# else 103207753Smm /* Use the standard inttypes.h. */ 104207753Smm# ifdef __cplusplus 105207753Smm /* 106207753Smm * C99 sections 7.18.2 and 7.18.4 specify 107207753Smm * that C++ implementations define the limit 108207753Smm * and constant macros only if specifically 109207753Smm * requested. Note that if you want the 110207753Smm * format macros (PRIu64 etc.) too, you need 111207753Smm * to define __STDC_FORMAT_MACROS before 112207753Smm * including lzma.h, since re-including 113207753Smm * inttypes.h with __STDC_FORMAT_MACROS 114207753Smm * defined doesn't necessarily work. 115207753Smm */ 116207753Smm# ifndef __STDC_LIMIT_MACROS 117207753Smm# define __STDC_LIMIT_MACROS 1 118207753Smm# endif 119207753Smm# ifndef __STDC_CONSTANT_MACROS 120207753Smm# define __STDC_CONSTANT_MACROS 1 121207753Smm# endif 122207753Smm# endif 123207753Smm 124207753Smm# include <inttypes.h> 125207753Smm# endif 126207753Smm 127207753Smm /* 128207753Smm * Some old systems have only the typedefs in inttypes.h, and 129207753Smm * lack all the macros. For those systems, we need a few more 130207753Smm * hacks. We assume that unsigned int is 32-bit and unsigned 131207753Smm * long is either 32-bit or 64-bit. If these hacks aren't 132207753Smm * enough, the application has to setup the types manually 133207753Smm * before including lzma.h. 134207753Smm */ 135207753Smm# ifndef UINT32_C 136207753Smm# if defined(_WIN32) && defined(_MSC_VER) 137207753Smm# define UINT32_C(n) n ## UI32 138207753Smm# else 139207753Smm# define UINT32_C(n) n ## U 140207753Smm# endif 141207753Smm# endif 142207753Smm 143207753Smm# ifndef UINT64_C 144207753Smm# if defined(_WIN32) && defined(_MSC_VER) 145207753Smm# define UINT64_C(n) n ## UI64 146207753Smm# else 147207753Smm /* Get ULONG_MAX. */ 148207753Smm# include <limits.h> 149207753Smm# if ULONG_MAX == 4294967295UL 150207753Smm# define UINT64_C(n) n ## ULL 151207753Smm# else 152207753Smm# define UINT64_C(n) n ## UL 153207753Smm# endif 154207753Smm# endif 155207753Smm# endif 156207753Smm 157207753Smm# ifndef UINT32_MAX 158207753Smm# define UINT32_MAX (UINT32_C(4294967295)) 159207753Smm# endif 160207753Smm 161207753Smm# ifndef UINT64_MAX 162207753Smm# define UINT64_MAX (UINT64_C(18446744073709551615)) 163207753Smm# endif 164207753Smm# endif 165207753Smm#endif /* ifdef LZMA_MANUAL_HEADERS */ 166207753Smm 167207753Smm 168207753Smm/****************** 169207753Smm * LZMA_API macro * 170207753Smm ******************/ 171207753Smm 172207753Smm/* 173207753Smm * Some systems require that the functions and function pointers are 174207753Smm * declared specially in the headers. LZMA_API_IMPORT is for importing 175207753Smm * symbols and LZMA_API_CALL is to specify the calling convention. 176207753Smm * 177207753Smm * By default it is assumed that the application will link dynamically 178207753Smm * against liblzma. #define LZMA_API_STATIC in your application if you 179207753Smm * want to link against static liblzma. If you don't care about portability 180207753Smm * to operating systems like Windows, or at least don't care about linking 181207753Smm * against static liblzma on them, don't worry about LZMA_API_STATIC. That 182207753Smm * is, most developers will never need to use LZMA_API_STATIC. 183207753Smm * 184207753Smm * The GCC variants are a special case on Windows (Cygwin and MinGW). 185207753Smm * We rely on GCC doing the right thing with its auto-import feature, 186207753Smm * and thus don't use __declspec(dllimport). This way developers don't 187207753Smm * need to worry about LZMA_API_STATIC. Also the calling convention is 188207753Smm * omitted on Cygwin but not on MinGW. 189207753Smm */ 190207753Smm#ifndef LZMA_API_IMPORT 191207753Smm# if !defined(LZMA_API_STATIC) && defined(_WIN32) && !defined(__GNUC__) 192207753Smm# define LZMA_API_IMPORT __declspec(dllimport) 193207753Smm# else 194207753Smm# define LZMA_API_IMPORT 195207753Smm# endif 196207753Smm#endif 197207753Smm 198207753Smm#ifndef LZMA_API_CALL 199207753Smm# if defined(_WIN32) && !defined(__CYGWIN__) 200207753Smm# define LZMA_API_CALL __cdecl 201207753Smm# else 202207753Smm# define LZMA_API_CALL 203207753Smm# endif 204207753Smm#endif 205207753Smm 206207753Smm#ifndef LZMA_API 207207753Smm# define LZMA_API(type) LZMA_API_IMPORT type LZMA_API_CALL 208207753Smm#endif 209207753Smm 210207753Smm 211207753Smm/*********** 212207753Smm * nothrow * 213207753Smm ***********/ 214207753Smm 215207753Smm/* 216207753Smm * None of the functions in liblzma may throw an exception. Even 217207753Smm * the functions that use callback functions won't throw exceptions, 218207753Smm * because liblzma would break if a callback function threw an exception. 219207753Smm */ 220207753Smm#ifndef lzma_nothrow 221207753Smm# if defined(__cplusplus) 222334607Sdelphij# if __cplusplus >= 201103L 223334607Sdelphij# define lzma_nothrow noexcept 224334607Sdelphij# else 225334607Sdelphij# define lzma_nothrow throw() 226334607Sdelphij# endif 227360523Sdelphij# elif defined(__GNUC__) && (__GNUC__ > 3 \ 228360523Sdelphij || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)) 229207753Smm# define lzma_nothrow __attribute__((__nothrow__)) 230207753Smm# else 231207753Smm# define lzma_nothrow 232207753Smm# endif 233207753Smm#endif 234207753Smm 235207753Smm 236207753Smm/******************** 237207753Smm * GNU C extensions * 238207753Smm ********************/ 239207753Smm 240207753Smm/* 241207753Smm * GNU C extensions are used conditionally in the public API. It doesn't 242207753Smm * break anything if these are sometimes enabled and sometimes not, only 243207753Smm * affects warnings and optimizations. 244207753Smm */ 245360523Sdelphij#if defined(__GNUC__) && __GNUC__ >= 3 246207753Smm# ifndef lzma_attribute 247207753Smm# define lzma_attribute(attr) __attribute__(attr) 248207753Smm# endif 249207753Smm 250207753Smm /* warn_unused_result was added in GCC 3.4. */ 251207753Smm# ifndef lzma_attr_warn_unused_result 252207753Smm# if __GNUC__ == 3 && __GNUC_MINOR__ < 4 253207753Smm# define lzma_attr_warn_unused_result 254207753Smm# endif 255207753Smm# endif 256207753Smm 257207753Smm#else 258207753Smm# ifndef lzma_attribute 259207753Smm# define lzma_attribute(attr) 260207753Smm# endif 261207753Smm#endif 262207753Smm 263207753Smm 264207753Smm#ifndef lzma_attr_pure 265207753Smm# define lzma_attr_pure lzma_attribute((__pure__)) 266207753Smm#endif 267207753Smm 268207753Smm#ifndef lzma_attr_const 269207753Smm# define lzma_attr_const lzma_attribute((__const__)) 270207753Smm#endif 271207753Smm 272207753Smm#ifndef lzma_attr_warn_unused_result 273207753Smm# define lzma_attr_warn_unused_result \ 274207753Smm lzma_attribute((__warn_unused_result__)) 275207753Smm#endif 276207753Smm 277207753Smm 278207753Smm/************** 279207753Smm * Subheaders * 280207753Smm **************/ 281207753Smm 282207753Smm#ifdef __cplusplus 283207753Smmextern "C" { 284207753Smm#endif 285207753Smm 286207753Smm/* 287207753Smm * Subheaders check that this is defined. It is to prevent including 288207753Smm * them directly from applications. 289207753Smm */ 290207753Smm#define LZMA_H_INTERNAL 1 291207753Smm 292207753Smm/* Basic features */ 293207753Smm#include "lzma/version.h" 294207753Smm#include "lzma/base.h" 295207753Smm#include "lzma/vli.h" 296207753Smm#include "lzma/check.h" 297207753Smm 298207753Smm/* Filters */ 299207753Smm#include "lzma/filter.h" 300207753Smm#include "lzma/bcj.h" 301207753Smm#include "lzma/delta.h" 302278433Srpaulo#include "lzma/lzma12.h" 303207753Smm 304207753Smm/* Container formats */ 305207753Smm#include "lzma/container.h" 306207753Smm 307207753Smm/* Advanced features */ 308207753Smm#include "lzma/stream_flags.h" 309207753Smm#include "lzma/block.h" 310207753Smm#include "lzma/index.h" 311207753Smm#include "lzma/index_hash.h" 312207753Smm 313207753Smm/* Hardware information */ 314207753Smm#include "lzma/hardware.h" 315207753Smm 316207753Smm/* 317207753Smm * All subheaders included. Undefine LZMA_H_INTERNAL to prevent applications 318207753Smm * re-including the subheaders. 319207753Smm */ 320207753Smm#undef LZMA_H_INTERNAL 321207753Smm 322207753Smm#ifdef __cplusplus 323207753Smm} 324207753Smm#endif 325207753Smm 326207753Smm#endif /* ifndef LZMA_H */ 327