deps: Add liblmza

Used by the update module on windows.
This commit is contained in:
jp9000
2017-02-20 04:47:20 -08:00
parent f1aba65bbb
commit 54683c981a
162 changed files with 27405 additions and 0 deletions

50
deps/lzma/common/common_w32res.rc vendored Normal file
View File

@@ -0,0 +1,50 @@
/*
* Author: Lasse Collin
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
#include <winresrc.h>
#include "config.h"
#define LZMA_H_INTERNAL
#define LZMA_H_INTERNAL_RC
#include "lzma/version.h"
#ifndef MY_BUILD
# define MY_BUILD 0
#endif
#define MY_VERSION LZMA_VERSION_MAJOR,LZMA_VERSION_MINOR,LZMA_VERSION_PATCH,MY_BUILD
#define MY_FILENAME MY_NAME MY_SUFFIX
#define MY_COMPANY "The Tukaani Project <http://tukaani.org/>"
#define MY_PRODUCT PACKAGE_NAME " <" PACKAGE_URL ">"
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
VS_VERSION_INFO VERSIONINFO
FILEVERSION MY_VERSION
PRODUCTVERSION MY_VERSION
FILEFLAGSMASK VS_FFI_FILEFLAGSMASK
FILEFLAGS 0
FILEOS VOS_NT_WINDOWS32
FILETYPE MY_TYPE
FILESUBTYPE 0x0L
BEGIN
BLOCK "StringFileInfo"
BEGIN
BLOCK "040904b0"
BEGIN
VALUE "CompanyName", MY_COMPANY
VALUE "FileDescription", MY_DESC
VALUE "FileVersion", LZMA_VERSION_STRING
VALUE "InternalName", MY_NAME
VALUE "OriginalFilename", MY_FILENAME
VALUE "ProductName", MY_PRODUCT
VALUE "ProductVersion", LZMA_VERSION_STRING
END
END
BLOCK "VarFileInfo"
BEGIN
VALUE "Translation", 0x409, 1200
END
END

42
deps/lzma/common/mythread.h vendored Normal file
View File

@@ -0,0 +1,42 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file mythread.h
/// \brief Wrappers for threads
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "sysdefs.h"
#ifdef HAVE_PTHREAD
# include <pthread.h>
# define mythread_once(func) \
do { \
static pthread_once_t once_ = PTHREAD_ONCE_INIT; \
pthread_once(&once_, &func); \
} while (0)
# define mythread_sigmask(how, set, oset) \
pthread_sigmask(how, set, oset)
#else
# define mythread_once(func) \
do { \
static bool once_ = false; \
if (!once_) { \
func(); \
once_ = true; \
} \
} while (0)
# define mythread_sigmask(how, set, oset) \
sigprocmask(how, set, oset)
#endif

199
deps/lzma/common/sysdefs.h vendored Normal file
View File

@@ -0,0 +1,199 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file sysdefs.h
/// \brief Common includes, definitions, system-specific things etc.
///
/// This file is used also by the lzma command line tool, that's why this
/// file is separate from common.h.
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef LZMA_SYSDEFS_H
#define LZMA_SYSDEFS_H
//////////////
// Includes //
//////////////
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#if defined(_MSC_VER) && _MSC_VER >= 1400
# define VC_EXTRALEAN
# include <Windows.h>
# include <intrin.h>
# undef VC_EXTRALEAN
#endif
// Get standard-compliant stdio functions under MinGW and MinGW-w64.
#ifdef __MINGW32__
# define __USE_MINGW_ANSI_STDIO 1
#endif
// size_t and NULL
#include <stddef.h>
#ifdef HAVE_INTTYPES_H
# include <inttypes.h>
#endif
// C99 says that inttypes.h always includes stdint.h, but some systems
// don't do that, and require including stdint.h separately.
#ifdef HAVE_STDINT_H
# include <stdint.h>
#endif
// Some pre-C99 systems have SIZE_MAX in limits.h instead of stdint.h. The
// limits are also used to figure out some macros missing from pre-C99 systems.
#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.
// Note that this duplicates some code from lzma.h, but this is better since
// we can work without inttypes.h thanks to Autoconf tests.
#ifndef UINT32_C
# if UINT_MAX != 4294967295U
# error UINT32_C is not defined and unsigned int is not 32-bit.
# endif
# 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
#ifndef PRIX32
# define PRIX32 "X"
#endif
#if ULONG_MAX == 4294967295UL
# ifndef UINT64_C
# define UINT64_C(n) n ## ULL
# endif
# ifndef PRIu64
# define PRIu64 "llu"
# endif
# ifndef PRIx64
# define PRIx64 "llx"
# 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
# ifndef PRIX64
# define PRIX64 "lX"
# endif
#endif
#ifndef UINT64_MAX
# define UINT64_MAX UINT64_C(18446744073709551615)
#endif
// Incorrect(?) SIZE_MAX:
// - Interix headers typedef size_t to unsigned long,
// but a few lines later define SIZE_MAX to INT32_MAX.
// - SCO OpenServer (x86) headers typedef size_t to unsigned int
// but define SIZE_MAX to INT32_MAX.
#if defined(__INTERIX) || defined(_SCO_DS)
# undef SIZE_MAX
#endif
// The code currently assumes that size_t is either 32-bit or 64-bit.
#ifndef SIZE_MAX
# if SIZEOF_SIZE_T == 4
# define SIZE_MAX UINT32_MAX
# elif SIZEOF_SIZE_T == 8
# define SIZE_MAX UINT64_MAX
# else
# error size_t is not 32-bit or 64-bit
# endif
#endif
#if SIZE_MAX != UINT32_MAX && SIZE_MAX != UINT64_MAX
# error size_t is not 32-bit or 64-bit
#endif
#include <stdlib.h>
#include <assert.h>
// Pre-C99 systems lack stdbool.h. All the code in LZMA Utils must be written
// so that it works with fake bool type, for example:
//
// bool foo = (flags & 0x100) != 0;
// bool bar = !!(flags & 0x100);
//
// This works with the real C99 bool but breaks with fake bool:
//
// bool baz = (flags & 0x100);
//
#ifdef HAVE_STDBOOL_H
# include <stdbool.h>
#else
# if ! HAVE__BOOL
typedef unsigned char _Bool;
# endif
# define bool _Bool
# define false 0
# define true 1
# define __bool_true_false_are_defined 1
#endif
// string.h should be enough but let's include strings.h and memory.h too if
// they exists, since that shouldn't do any harm, but may improve portability.
#ifdef HAVE_STRING_H
# include <string.h>
#endif
#ifdef HAVE_STRINGS_H
# include <strings.h>
#endif
#ifdef HAVE_MEMORY_H
# include <memory.h>
#endif
////////////
// Macros //
////////////
#undef memzero
#define memzero(s, n) memset(s, 0, n)
// NOTE: Avoid using MIN() and MAX(), because even conditionally defining
// those macros can cause some portability trouble, since on some systems
// the system headers insist defining their own versions.
#define my_min(x, y) ((x) < (y) ? (x) : (y))
#define my_max(x, y) ((x) > (y) ? (x) : (y))
#ifndef ARRAY_SIZE
# define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
#endif
#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 3) || __GNUC__ > 4
# define lzma_attr_alloc_size(x) __attribute__((__alloc_size__(x)))
#else
# define lzma_attr_alloc_size(x)
#endif
#endif

71
deps/lzma/common/tuklib_common.h vendored Normal file
View File

@@ -0,0 +1,71 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_common.h
/// \brief Common definitions for tuklib modules
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef TUKLIB_COMMON_H
#define TUKLIB_COMMON_H
// The config file may be replaced by a package-specific file.
// It should include at least stddef.h, inttypes.h, and limits.h.
#include "tuklib_config.h"
// TUKLIB_SYMBOL_PREFIX is prefixed to all symbols exported by
// the tuklib modules. If you use a tuklib module in a library,
// you should use TUKLIB_SYMBOL_PREFIX to make sure that there
// are no symbol conflicts in case someone links your library
// into application that also uses the same tuklib module.
#ifndef TUKLIB_SYMBOL_PREFIX
# define TUKLIB_SYMBOL_PREFIX
#endif
#define TUKLIB_CAT_X(a, b) a ## b
#define TUKLIB_CAT(a, b) TUKLIB_CAT_X(a, b)
#ifndef TUKLIB_SYMBOL
# define TUKLIB_SYMBOL(sym) TUKLIB_CAT(TUKLIB_SYMBOL_PREFIX, sym)
#endif
#ifndef TUKLIB_DECLS_BEGIN
# ifdef __cplusplus
# define TUKLIB_DECLS_BEGIN extern "C" {
# else
# define TUKLIB_DECLS_BEGIN
# endif
#endif
#ifndef TUKLIB_DECLS_END
# ifdef __cplusplus
# define TUKLIB_DECLS_END }
# else
# define TUKLIB_DECLS_END
# endif
#endif
#if defined(__GNUC__) && defined(__GNUC_MINOR__)
# define TUKLIB_GNUC_REQ(major, minor) \
((__GNUC__ == (major) && __GNUC_MINOR__ >= (minor)) \
|| __GNUC__ > (major))
#else
# define TUKLIB_GNUC_REQ(major, minor) 0
#endif
#if TUKLIB_GNUC_REQ(2, 5)
# define tuklib_attr_noreturn __attribute__((__noreturn__))
#else
# define tuklib_attr_noreturn
#endif
#if (defined(_WIN32) && !defined(__CYGWIN__)) \
|| defined(__OS2__) || defined(__MSDOS__)
# define TUKLIB_DOSLIKE 1
#endif
#endif

7
deps/lzma/common/tuklib_config.h vendored Normal file
View File

@@ -0,0 +1,7 @@
#ifdef HAVE_CONFIG_H
# include "sysdefs.h"
#else
# include <stddef.h>
# include <inttypes.h>
# include <limits.h>
#endif

62
deps/lzma/common/tuklib_cpucores.c vendored Normal file
View File

@@ -0,0 +1,62 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_cpucores.c
/// \brief Get the number of CPU cores online
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "tuklib_cpucores.h"
#if defined(TUKLIB_CPUCORES_SYSCTL)
# ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
# endif
# include <sys/sysctl.h>
#elif defined(TUKLIB_CPUCORES_SYSCONF)
# include <unistd.h>
// HP-UX
#elif defined(TUKLIB_CPUCORES_PSTAT_GETDYNAMIC)
# include <sys/param.h>
# include <sys/pstat.h>
#endif
extern uint32_t
tuklib_cpucores(void)
{
uint32_t ret = 0;
#if defined(TUKLIB_CPUCORES_SYSCTL)
int name[2] = { CTL_HW, HW_NCPU };
int cpus;
size_t cpus_size = sizeof(cpus);
if (sysctl(name, 2, &cpus, &cpus_size, NULL, 0) != -1
&& cpus_size == sizeof(cpus) && cpus > 0)
ret = cpus;
#elif defined(TUKLIB_CPUCORES_SYSCONF)
# ifdef _SC_NPROCESSORS_ONLN
// Most systems
const long cpus = sysconf(_SC_NPROCESSORS_ONLN);
# else
// IRIX
const long cpus = sysconf(_SC_NPROC_ONLN);
# endif
if (cpus > 0)
ret = cpus;
#elif defined(TUKLIB_CPUCORES_PSTAT_GETDYNAMIC)
struct pst_dynamic pst;
if (pstat_getdynamic(&pst, sizeof(pst), 1, 0) != -1)
ret = pst.psd_proc_cnt;
#endif
return ret;
}

23
deps/lzma/common/tuklib_cpucores.h vendored Normal file
View File

@@ -0,0 +1,23 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_cpucores.h
/// \brief Get the number of CPU cores online
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef TUKLIB_CPUCORES_H
#define TUKLIB_CPUCORES_H
#include "tuklib_common.h"
TUKLIB_DECLS_BEGIN
#define tuklib_cpucores TUKLIB_SYMBOL(tuklib_cpucores)
extern uint32_t tuklib_cpucores(void);
TUKLIB_DECLS_END
#endif

57
deps/lzma/common/tuklib_exit.c vendored Normal file
View File

@@ -0,0 +1,57 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_exit.c
/// \brief Close stdout and stderr, and exit
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "tuklib_common.h"
#include <stdlib.h>
#include <stdio.h>
#include "tuklib_gettext.h"
#include "tuklib_progname.h"
#include "tuklib_exit.h"
extern void
tuklib_exit(int status, int err_status, int show_error)
{
if (status != err_status) {
// Close stdout. If something goes wrong,
// print an error message to stderr.
const int ferror_err = ferror(stdout);
const int fclose_err = fclose(stdout);
if (ferror_err || fclose_err) {
status = err_status;
// If it was fclose() that failed, we have the reason
// in errno. If only ferror() indicated an error,
// we have no idea what the reason was.
if (show_error)
fprintf(stderr, "%s: %s: %s\n", progname,
_("Writing to standard "
"output failed"),
fclose_err ? strerror(errno)
: _("Unknown error"));
}
}
if (status != err_status) {
// Close stderr. If something goes wrong, there's
// nothing where we could print an error message.
// Just set the exit status.
const int ferror_err = ferror(stderr);
const int fclose_err = fclose(stderr);
if (fclose_err || ferror_err)
status = err_status;
}
exit(status);
}

25
deps/lzma/common/tuklib_exit.h vendored Normal file
View File

@@ -0,0 +1,25 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_exit.h
/// \brief Close stdout and stderr, and exit
/// \note Requires tuklib_progname and tuklib_gettext modules
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef TUKLIB_EXIT_H
#define TUKLIB_EXIT_H
#include "tuklib_common.h"
TUKLIB_DECLS_BEGIN
#define tuklib_exit TUKLIB_SYMBOL(tuklib_exit)
extern void tuklib_exit(int status, int err_status, int show_error)
tuklib_attr_noreturn;
TUKLIB_DECLS_END
#endif

44
deps/lzma/common/tuklib_gettext.h vendored Normal file
View File

@@ -0,0 +1,44 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_gettext.h
/// \brief Wrapper for gettext and friends
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef TUKLIB_GETTEXT_H
#define TUKLIB_GETTEXT_H
#include "tuklib_common.h"
#include <locale.h>
#ifndef TUKLIB_GETTEXT
# ifdef ENABLE_NLS
# define TUKLIB_GETTEXT 1
# else
# define TUKLIB_GETTEXT 0
# endif
#endif
#if TUKLIB_GETTEXT
# include <libintl.h>
# define tuklib_gettext_init(package, localedir) \
do { \
setlocale(LC_ALL, ""); \
bindtextdomain(package, localedir); \
textdomain(package); \
} while (0)
# define _(msgid) gettext(msgid)
#else
# define tuklib_gettext_init(package, localedir) \
setlocale(LC_ALL, "")
# define _(msgid) (msgid)
# define ngettext(msgid1, msgid2, n) ((n) == 1 ? (msgid1) : (msgid2))
#endif
#define N_(msgid) msgid
#endif

523
deps/lzma/common/tuklib_integer.h vendored Normal file
View File

@@ -0,0 +1,523 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_integer.h
/// \brief Various integer and bit operations
///
/// This file provides macros or functions to do some basic integer and bit
/// operations.
///
/// Endianness related integer operations (XX = 16, 32, or 64; Y = b or l):
/// - Byte swapping: bswapXX(num)
/// - Byte order conversions to/from native: convXXYe(num)
/// - Aligned reads: readXXYe(ptr)
/// - Aligned writes: writeXXYe(ptr, num)
/// - Unaligned reads (16/32-bit only): unaligned_readXXYe(ptr)
/// - Unaligned writes (16/32-bit only): unaligned_writeXXYe(ptr, num)
///
/// Since they can macros, the arguments should have no side effects since
/// they may be evaluated more than once.
///
/// \todo PowerPC and possibly some other architectures support
/// byte swapping load and store instructions. This file
/// doesn't take advantage of those instructions.
///
/// Bit scan operations for non-zero 32-bit integers:
/// - Bit scan reverse (find highest non-zero bit): bsr32(num)
/// - Count leading zeros: clz32(num)
/// - Count trailing zeros: ctz32(num)
/// - Bit scan forward (simply an alias for ctz32()): bsf32(num)
///
/// The above bit scan operations return 0-31. If num is zero,
/// the result is undefined.
//
// Authors: Lasse Collin
// Joachim Henke
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef TUKLIB_INTEGER_H
#define TUKLIB_INTEGER_H
#include "tuklib_common.h"
////////////////////////////////////////
// Operating system specific features //
////////////////////////////////////////
#if defined(HAVE_BYTESWAP_H)
// glibc, uClibc, dietlibc
# include <byteswap.h>
# ifdef HAVE_BSWAP_16
# define bswap16(num) bswap_16(num)
# endif
# ifdef HAVE_BSWAP_32
# define bswap32(num) bswap_32(num)
# endif
# ifdef HAVE_BSWAP_64
# define bswap64(num) bswap_64(num)
# endif
#elif defined(HAVE_SYS_ENDIAN_H)
// *BSDs and Darwin
# include <sys/endian.h>
#elif defined(HAVE_SYS_BYTEORDER_H)
// Solaris
# include <sys/byteorder.h>
# ifdef BSWAP_16
# define bswap16(num) BSWAP_16(num)
# endif
# ifdef BSWAP_32
# define bswap32(num) BSWAP_32(num)
# endif
# ifdef BSWAP_64
# define bswap64(num) BSWAP_64(num)
# endif
# ifdef BE_16
# define conv16be(num) BE_16(num)
# endif
# ifdef BE_32
# define conv32be(num) BE_32(num)
# endif
# ifdef BE_64
# define conv64be(num) BE_64(num)
# endif
# ifdef LE_16
# define conv16le(num) LE_16(num)
# endif
# ifdef LE_32
# define conv32le(num) LE_32(num)
# endif
# ifdef LE_64
# define conv64le(num) LE_64(num)
# endif
#endif
///////////////////
// Byte swapping //
///////////////////
#ifndef bswap16
# define bswap16(num) \
(((uint16_t)(num) << 8) | ((uint16_t)(num) >> 8))
#endif
#ifndef bswap32
# define bswap32(num) \
( (((uint32_t)(num) << 24) ) \
| (((uint32_t)(num) << 8) & UINT32_C(0x00FF0000)) \
| (((uint32_t)(num) >> 8) & UINT32_C(0x0000FF00)) \
| (((uint32_t)(num) >> 24) ) )
#endif
#ifndef bswap64
# define bswap64(num) \
( (((uint64_t)(num) << 56) ) \
| (((uint64_t)(num) << 40) & UINT64_C(0x00FF000000000000)) \
| (((uint64_t)(num) << 24) & UINT64_C(0x0000FF0000000000)) \
| (((uint64_t)(num) << 8) & UINT64_C(0x000000FF00000000)) \
| (((uint64_t)(num) >> 8) & UINT64_C(0x00000000FF000000)) \
| (((uint64_t)(num) >> 24) & UINT64_C(0x0000000000FF0000)) \
| (((uint64_t)(num) >> 40) & UINT64_C(0x000000000000FF00)) \
| (((uint64_t)(num) >> 56) ) )
#endif
// Define conversion macros using the basic byte swapping macros.
#ifdef WORDS_BIGENDIAN
# ifndef conv16be
# define conv16be(num) ((uint16_t)(num))
# endif
# ifndef conv32be
# define conv32be(num) ((uint32_t)(num))
# endif
# ifndef conv64be
# define conv64be(num) ((uint64_t)(num))
# endif
# ifndef conv16le
# define conv16le(num) bswap16(num)
# endif
# ifndef conv32le
# define conv32le(num) bswap32(num)
# endif
# ifndef conv64le
# define conv64le(num) bswap64(num)
# endif
#else
# ifndef conv16be
# define conv16be(num) bswap16(num)
# endif
# ifndef conv32be
# define conv32be(num) bswap32(num)
# endif
# ifndef conv64be
# define conv64be(num) bswap64(num)
# endif
# ifndef conv16le
# define conv16le(num) ((uint16_t)(num))
# endif
# ifndef conv32le
# define conv32le(num) ((uint32_t)(num))
# endif
# ifndef conv64le
# define conv64le(num) ((uint64_t)(num))
# endif
#endif
//////////////////////////////
// Aligned reads and writes //
//////////////////////////////
static inline uint16_t
read16be(const uint8_t *buf)
{
uint16_t num = *(const uint16_t *)buf;
return conv16be(num);
}
static inline uint16_t
read16le(const uint8_t *buf)
{
uint16_t num = *(const uint16_t *)buf;
return conv16le(num);
}
static inline uint32_t
read32be(const uint8_t *buf)
{
uint32_t num = *(const uint32_t *)buf;
return conv32be(num);
}
static inline uint32_t
read32le(const uint8_t *buf)
{
uint32_t num = *(const uint32_t *)buf;
return conv32le(num);
}
static inline uint64_t
read64be(const uint8_t *buf)
{
uint64_t num = *(const uint64_t *)buf;
return conv64be(num);
}
static inline uint64_t
read64le(const uint8_t *buf)
{
uint64_t num = *(const uint64_t *)buf;
return conv64le(num);
}
// NOTE: Possible byte swapping must be done in a macro to allow GCC
// to optimize byte swapping of constants when using glibc's or *BSD's
// byte swapping macros. The actual write is done in an inline function
// to make type checking of the buf pointer possible similarly to readXXYe()
// functions.
#define write16be(buf, num) write16ne((buf), conv16be(num))
#define write16le(buf, num) write16ne((buf), conv16le(num))
#define write32be(buf, num) write32ne((buf), conv32be(num))
#define write32le(buf, num) write32ne((buf), conv32le(num))
#define write64be(buf, num) write64ne((buf), conv64be(num))
#define write64le(buf, num) write64ne((buf), conv64le(num))
static inline void
write16ne(uint8_t *buf, uint16_t num)
{
*(uint16_t *)buf = num;
return;
}
static inline void
write32ne(uint8_t *buf, uint32_t num)
{
*(uint32_t *)buf = num;
return;
}
static inline void
write64ne(uint8_t *buf, uint64_t num)
{
*(uint64_t *)buf = num;
return;
}
////////////////////////////////
// Unaligned reads and writes //
////////////////////////////////
// NOTE: TUKLIB_FAST_UNALIGNED_ACCESS indicates only support for 16-bit and
// 32-bit unaligned integer loads and stores. It's possible that 64-bit
// unaligned access doesn't work or is slower than byte-by-byte access.
// Since unaligned 64-bit is probably not needed as often as 16-bit or
// 32-bit, we simply don't support 64-bit unaligned access for now.
#ifdef TUKLIB_FAST_UNALIGNED_ACCESS
# define unaligned_read16be read16be
# define unaligned_read16le read16le
# define unaligned_read32be read32be
# define unaligned_read32le read32le
# define unaligned_write16be write16be
# define unaligned_write16le write16le
# define unaligned_write32be write32be
# define unaligned_write32le write32le
#else
static inline uint16_t
unaligned_read16be(const uint8_t *buf)
{
uint16_t num = ((uint16_t)buf[0] << 8) | (uint16_t)buf[1];
return num;
}
static inline uint16_t
unaligned_read16le(const uint8_t *buf)
{
uint16_t num = ((uint16_t)buf[0]) | ((uint16_t)buf[1] << 8);
return num;
}
static inline uint32_t
unaligned_read32be(const uint8_t *buf)
{
uint32_t num = (uint32_t)buf[0] << 24;
num |= (uint32_t)buf[1] << 16;
num |= (uint32_t)buf[2] << 8;
num |= (uint32_t)buf[3];
return num;
}
static inline uint32_t
unaligned_read32le(const uint8_t *buf)
{
uint32_t num = (uint32_t)buf[0];
num |= (uint32_t)buf[1] << 8;
num |= (uint32_t)buf[2] << 16;
num |= (uint32_t)buf[3] << 24;
return num;
}
static inline void
unaligned_write16be(uint8_t *buf, uint16_t num)
{
buf[0] = num >> 8;
buf[1] = num;
return;
}
static inline void
unaligned_write16le(uint8_t *buf, uint16_t num)
{
buf[0] = num;
buf[1] = num >> 8;
return;
}
static inline void
unaligned_write32be(uint8_t *buf, uint32_t num)
{
buf[0] = num >> 24;
buf[1] = num >> 16;
buf[2] = num >> 8;
buf[3] = num;
return;
}
static inline void
unaligned_write32le(uint8_t *buf, uint32_t num)
{
buf[0] = num;
buf[1] = num >> 8;
buf[2] = num >> 16;
buf[3] = num >> 24;
return;
}
#endif
static inline uint32_t
bsr32(uint32_t n)
{
// Check for ICC first, since it tends to define __GNUC__ too.
#if defined(__INTEL_COMPILER)
return _bit_scan_reverse(n);
#elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX == UINT32_MAX
// GCC >= 3.4 has __builtin_clz(), which gives good results on
// multiple architectures. On x86, __builtin_clz() ^ 31U becomes
// either plain BSR (so the XOR gets optimized away) or LZCNT and
// XOR (if -march indicates that SSE4a instructions are supported).
return __builtin_clz(n) ^ 31U;
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
uint32_t i;
__asm__("bsrl %1, %0" : "=r" (i) : "rm" (n));
return i;
#elif defined(_MSC_VER) && _MSC_VER >= 1400
// MSVC isn't supported by tuklib, but since this code exists,
// it doesn't hurt to have it here anyway.
uint32_t i;
_BitScanReverse((DWORD *)&i, n);
return i;
#else
uint32_t i = 31;
if ((n & UINT32_C(0xFFFF0000)) == 0) {
n <<= 16;
i = 15;
}
if ((n & UINT32_C(0xFF000000)) == 0) {
n <<= 8;
i -= 8;
}
if ((n & UINT32_C(0xF0000000)) == 0) {
n <<= 4;
i -= 4;
}
if ((n & UINT32_C(0xC0000000)) == 0) {
n <<= 2;
i -= 2;
}
if ((n & UINT32_C(0x80000000)) == 0)
--i;
return i;
#endif
}
static inline uint32_t
clz32(uint32_t n)
{
#if defined(__INTEL_COMPILER)
return _bit_scan_reverse(n) ^ 31U;
#elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX == UINT32_MAX
return __builtin_clz(n);
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
uint32_t i;
__asm__("bsrl %1, %0\n\t"
"xorl $31, %0"
: "=r" (i) : "rm" (n));
return i;
#elif defined(_MSC_VER) && _MSC_VER >= 1400
uint32_t i;
_BitScanReverse((DWORD *)&i, n);
return i ^ 31U;
#else
uint32_t i = 0;
if ((n & UINT32_C(0xFFFF0000)) == 0) {
n <<= 16;
i = 16;
}
if ((n & UINT32_C(0xFF000000)) == 0) {
n <<= 8;
i += 8;
}
if ((n & UINT32_C(0xF0000000)) == 0) {
n <<= 4;
i += 4;
}
if ((n & UINT32_C(0xC0000000)) == 0) {
n <<= 2;
i += 2;
}
if ((n & UINT32_C(0x80000000)) == 0)
++i;
return i;
#endif
}
static inline uint32_t
ctz32(uint32_t n)
{
#if defined(__INTEL_COMPILER)
return _bit_scan_forward(n);
#elif TUKLIB_GNUC_REQ(3, 4) && UINT_MAX >= UINT32_MAX
return __builtin_ctz(n);
#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
uint32_t i;
__asm__("bsfl %1, %0" : "=r" (i) : "rm" (n));
return i;
#elif defined(_MSC_VER) && _MSC_VER >= 1400
uint32_t i;
_BitScanForward((DWORD *)&i, n);
return i;
#else
uint32_t i = 0;
if ((n & UINT32_C(0x0000FFFF)) == 0) {
n >>= 16;
i = 16;
}
if ((n & UINT32_C(0x000000FF)) == 0) {
n >>= 8;
i += 8;
}
if ((n & UINT32_C(0x0000000F)) == 0) {
n >>= 4;
i += 4;
}
if ((n & UINT32_C(0x00000003)) == 0) {
n >>= 2;
i += 2;
}
if ((n & UINT32_C(0x00000001)) == 0)
++i;
return i;
#endif
}
#define bsf32 ctz32
#endif

66
deps/lzma/common/tuklib_mbstr.h vendored Normal file
View File

@@ -0,0 +1,66 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_mstr.h
/// \brief Utility functions for handling multibyte strings
///
/// If not enough multibyte string support is available in the C library,
/// these functions keep working with the assumption that all strings
/// are in a single-byte character set without combining characters, e.g.
/// US-ASCII or ISO-8859-*.
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef TUKLIB_MBSTR_H
#define TUKLIB_MBSTR_H
#include "tuklib_common.h"
TUKLIB_DECLS_BEGIN
#define tuklib_mbstr_width TUKLIB_SYMBOL(tuklib_mbstr_width)
extern size_t tuklib_mbstr_width(const char *str, size_t *bytes);
///<
/// \brief Get the number of columns needed for the multibyte string
///
/// This is somewhat similar to wcswidth() but works on multibyte strings.
///
/// \param str String whose width is to be calculated. If the
/// current locale uses a multibyte character set
/// that has shift states, the string must begin
/// and end in the initial shift state.
/// \param bytes If this is not NULL, *bytes is set to the
/// value returned by strlen(str) (even if an
/// error occurs when calculating the width).
///
/// \return On success, the number of columns needed to display the
/// string e.g. in a terminal emulator is returned. On error,
/// (size_t)-1 is returned. Possible errors include invalid,
/// partial, or non-printable multibyte character in str, or
/// that str doesn't end in the initial shift state.
#define tuklib_mbstr_fw TUKLIB_SYMBOL(tuklib_mbstr_fw)
extern int tuklib_mbstr_fw(const char *str, int columns_min);
///<
/// \brief Get the field width for printf() e.g. to align table columns
///
/// Printing simple tables to a terminal can be done using the field field
/// feature in the printf() format string, but it works only with single-byte
/// character sets. To do the same with multibyte strings, tuklib_mbstr_fw()
/// can be used to calculate appropriate field width.
///
/// The behavior of this function is undefined, if
/// - str is NULL or not terminated with '\0';
/// - columns_min <= 0; or
/// - the calculated field width exceeds INT_MAX.
///
/// \return If tuklib_mbstr_width(str, NULL) fails, -1 is returned.
/// If str needs more columns than columns_min, zero is returned.
/// Otherwise a positive integer is returned, which can be
/// used as the field width, e.g. printf("%*s", fw, str).
TUKLIB_DECLS_END
#endif

31
deps/lzma/common/tuklib_mbstr_fw.c vendored Normal file
View File

@@ -0,0 +1,31 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_mstr_fw.c
/// \brief Get the field width for printf() e.g. to align table columns
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "tuklib_mbstr.h"
extern int
tuklib_mbstr_fw(const char *str, int columns_min)
{
size_t len;
const size_t width = tuklib_mbstr_width(str, &len);
if (width == (size_t)-1)
return -1;
if (width > (size_t)columns_min)
return 0;
if (width < (size_t)columns_min)
len += (size_t)columns_min - width;
return len;
}

64
deps/lzma/common/tuklib_mbstr_width.c vendored Normal file
View File

@@ -0,0 +1,64 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_mstr_width.c
/// \brief Calculate width of a multibyte string
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "tuklib_mbstr.h"
#if defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH)
# include <wchar.h>
#endif
extern size_t
tuklib_mbstr_width(const char *str, size_t *bytes)
{
const size_t len = strlen(str);
if (bytes != NULL)
*bytes = len;
#if !(defined(HAVE_MBRTOWC) && defined(HAVE_WCWIDTH))
// In single-byte mode, the width of the string is the same
// as its length.
return len;
#else
mbstate_t state;
memset(&state, 0, sizeof(state));
size_t width = 0;
size_t i = 0;
// Convert one multibyte character at a time to wchar_t
// and get its width using wcwidth().
while (i < len) {
wchar_t wc;
const size_t ret = mbrtowc(&wc, str + i, len - i, &state);
if (ret < 1 || ret > len)
return (size_t)-1;
i += ret;
const int wc_width = wcwidth(wc);
if (wc_width < 0)
return (size_t)-1;
width += wc_width;
}
// Require that the string ends in the initial shift state.
// This way the caller can be combine the string with other
// strings without needing to worry about the shift states.
if (!mbsinit(&state))
return (size_t)-1;
return width;
#endif
}

57
deps/lzma/common/tuklib_open_stdxxx.c vendored Normal file
View File

@@ -0,0 +1,57 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_open_stdxxx.c
/// \brief Make sure that file descriptors 0, 1, and 2 are open
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "tuklib_open_stdxxx.h"
#ifndef TUKLIB_DOSLIKE
# include <stdlib.h>
# include <errno.h>
# include <fcntl.h>
# include <unistd.h>
#endif
extern void
tuklib_open_stdxxx(int err_status)
{
#ifdef TUKLIB_DOSLIKE
// Do nothing, just silence warnings.
(void)err_status;
#else
for (int i = 0; i <= 2; ++i) {
// We use fcntl() to check if the file descriptor is open.
if (fcntl(i, F_GETFD) == -1 && errno == EBADF) {
// With stdin, we could use /dev/full so that
// writing to stdin would fail. However, /dev/full
// is Linux specific, and if the program tries to
// write to stdin, there's already a problem anyway.
const int fd = open("/dev/null", O_NOCTTY
| (i == 0 ? O_WRONLY : O_RDONLY));
if (fd != i) {
if (fd != -1)
(void)close(fd);
// Something went wrong. Exit with the
// exit status we were given. Don't try
// to print an error message, since stderr
// may very well be non-existent. This
// error should be extremely rare.
exit(err_status);
}
}
}
#endif
return;
}

23
deps/lzma/common/tuklib_open_stdxxx.h vendored Normal file
View File

@@ -0,0 +1,23 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_open_stdxxx.h
/// \brief Make sure that file descriptors 0, 1, and 2 are open
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef TUKLIB_OPEN_STDXXX_H
#define TUKLIB_OPEN_STDXXX_H
#include "tuklib_common.h"
TUKLIB_DECLS_BEGIN
#define tuklib_open_stdxx TUKLIB_SYMBOL(tuklib_open_stdxxx)
extern void tuklib_open_stdxxx(int err_status);
TUKLIB_DECLS_END
#endif

196
deps/lzma/common/tuklib_physmem.c vendored Normal file
View File

@@ -0,0 +1,196 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_physmem.c
/// \brief Get the amount of physical memory
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "tuklib_physmem.h"
// We want to use Windows-specific code on Cygwin, which also has memory
// information available via sysconf(), but on Cygwin 1.5 and older it
// gives wrong results (from our point of view).
#if defined(_WIN32) || defined(__CYGWIN__)
# ifndef _WIN32_WINNT
# define _WIN32_WINNT 0x0500
# endif
# include <windows.h>
#elif defined(__OS2__)
# define INCL_DOSMISC
# include <os2.h>
#elif defined(__DJGPP__)
# include <dpmi.h>
#elif defined(__VMS)
# include <lib$routines.h>
# include <syidef.h>
# include <ssdef.h>
// AIX
#elif defined(TUKLIB_PHYSMEM_AIX)
# include <sys/systemcfg.h>
#elif defined(TUKLIB_PHYSMEM_SYSCONF)
# include <unistd.h>
#elif defined(TUKLIB_PHYSMEM_SYSCTL)
# ifdef HAVE_SYS_PARAM_H
# include <sys/param.h>
# endif
# include <sys/sysctl.h>
// Tru64
#elif defined(TUKLIB_PHYSMEM_GETSYSINFO)
# include <sys/sysinfo.h>
# include <machine/hal_sysinfo.h>
// HP-UX
#elif defined(TUKLIB_PHYSMEM_PSTAT_GETSTATIC)
# include <sys/param.h>
# include <sys/pstat.h>
// IRIX
#elif defined(TUKLIB_PHYSMEM_GETINVENT_R)
# include <invent.h>
// This sysinfo() is Linux-specific.
#elif defined(TUKLIB_PHYSMEM_SYSINFO)
# include <sys/sysinfo.h>
#endif
extern uint64_t
tuklib_physmem(void)
{
uint64_t ret = 0;
#if defined(_WIN32) || defined(__CYGWIN__)
if ((GetVersion() & 0xFF) >= 5) {
// Windows 2000 and later have GlobalMemoryStatusEx() which
// supports reporting values greater than 4 GiB. To keep the
// code working also on older Windows versions, use
// GlobalMemoryStatusEx() conditionally.
HMODULE kernel32 = GetModuleHandle("kernel32.dll");
if (kernel32 != NULL) {
BOOL (WINAPI *gmse)(LPMEMORYSTATUSEX) = GetProcAddress(
kernel32, "GlobalMemoryStatusEx");
if (gmse != NULL) {
MEMORYSTATUSEX meminfo;
meminfo.dwLength = sizeof(meminfo);
if (gmse(&meminfo))
ret = meminfo.ullTotalPhys;
}
}
}
if (ret == 0) {
// GlobalMemoryStatus() is supported by Windows 95 and later,
// so it is fine to link against it unconditionally. Note that
// GlobalMemoryStatus() has no return value.
MEMORYSTATUS meminfo;
meminfo.dwLength = sizeof(meminfo);
GlobalMemoryStatus(&meminfo);
ret = meminfo.dwTotalPhys;
}
#elif defined(__OS2__)
unsigned long mem;
if (DosQuerySysInfo(QSV_TOTPHYSMEM, QSV_TOTPHYSMEM,
&mem, sizeof(mem)) == 0)
ret = mem;
#elif defined(__DJGPP__)
__dpmi_free_mem_info meminfo;
if (__dpmi_get_free_memory_information(&meminfo) == 0
&& meminfo.total_number_of_physical_pages
!= (unsigned long)-1)
ret = (uint64_t)meminfo.total_number_of_physical_pages * 4096;
#elif defined(__VMS)
int vms_mem;
int val = SYI$_MEMSIZE;
if (LIB$GETSYI(&val, &vms_mem, 0, 0, 0, 0) == SS$_NORMAL)
ret = (uint64_t)vms_mem * 8192;
#elif defined(TUKLIB_PHYSMEM_AIX)
ret = _system_configuration.physmem;
#elif defined(TUKLIB_PHYSMEM_SYSCONF)
const long pagesize = sysconf(_SC_PAGESIZE);
const long pages = sysconf(_SC_PHYS_PAGES);
if (pagesize != -1 && pages != -1)
// According to docs, pagesize * pages can overflow.
// Simple case is 32-bit box with 4 GiB or more RAM,
// which may report exactly 4 GiB of RAM, and "long"
// being 32-bit will overflow. Casting to uint64_t
// hopefully avoids overflows in the near future.
ret = (uint64_t)pagesize * (uint64_t)pages;
#elif defined(TUKLIB_PHYSMEM_SYSCTL)
int name[2] = {
CTL_HW,
#ifdef HW_PHYSMEM64
HW_PHYSMEM64
#else
HW_PHYSMEM
#endif
};
union {
uint32_t u32;
uint64_t u64;
} mem;
size_t mem_ptr_size = sizeof(mem.u64);
if (sysctl(name, 2, &mem.u64, &mem_ptr_size, NULL, 0) != -1) {
// IIRC, 64-bit "return value" is possible on some 64-bit
// BSD systems even with HW_PHYSMEM (instead of HW_PHYSMEM64),
// so support both.
if (mem_ptr_size == sizeof(mem.u64))
ret = mem.u64;
else if (mem_ptr_size == sizeof(mem.u32))
ret = mem.u32;
}
#elif defined(TUKLIB_PHYSMEM_GETSYSINFO)
// Docs are unclear if "start" is needed, but it doesn't hurt
// much to have it.
int memkb;
int start = 0;
if (getsysinfo(GSI_PHYSMEM, (caddr_t)&memkb, sizeof(memkb), &start)
!= -1)
ret = (uint64_t)memkb * 1024;
#elif defined(TUKLIB_PHYSMEM_PSTAT_GETSTATIC)
struct pst_static pst;
if (pstat_getstatic(&pst, sizeof(pst), 1, 0) != -1)
ret = (uint64_t)pst.physical_memory * (uint64_t)pst.page_size;
#elif defined(TUKLIB_PHYSMEM_GETINVENT_R)
inv_state_t *st = NULL;
if (setinvent_r(&st) != -1) {
inventory_t *i;
while ((i = getinvent_r(st)) != NULL) {
if (i->inv_class == INV_MEMORY
&& i->inv_type == INV_MAIN_MB) {
ret = (uint64_t)i->inv_state << 20;
break;
}
}
endinvent_r(st);
}
#elif defined(TUKLIB_PHYSMEM_SYSINFO)
struct sysinfo si;
if (sysinfo(&si) == 0)
ret = (uint64_t)si.totalram * si.mem_unit;
#endif
return ret;
}

28
deps/lzma/common/tuklib_physmem.h vendored Normal file
View File

@@ -0,0 +1,28 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_physmem.h
/// \brief Get the amount of physical memory
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef TUKLIB_PHYSMEM_H
#define TUKLIB_PHYSMEM_H
#include "tuklib_common.h"
TUKLIB_DECLS_BEGIN
#define tuklib_physmem TUKLIB_SYMBOL(tuklib_physmem)
extern uint64_t tuklib_physmem(void);
///<
/// \brief Get the amount of physical memory in bytes
///
/// \return Amount of physical memory in bytes. On error, zero is
/// returned.
TUKLIB_DECLS_END
#endif

50
deps/lzma/common/tuklib_progname.c vendored Normal file
View File

@@ -0,0 +1,50 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_progname.c
/// \brief Program name to be displayed in messages
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#include "tuklib_progname.h"
#include <string.h>
#if !HAVE_DECL_PROGRAM_INVOCATION_NAME
char *progname = NULL;
#endif
extern void
tuklib_progname_init(char **argv)
{
#ifdef TUKLIB_DOSLIKE
// On these systems, argv[0] always has the full path and .exe
// suffix even if the user just types the plain program name.
// We modify argv[0] to make it nicer to read.
// Strip the leading path.
char *p = argv[0] + strlen(argv[0]);
while (argv[0] < p && p[-1] != '/' && p[-1] != '\\')
--p;
argv[0] = p;
// Strip the .exe suffix.
p = strrchr(p, '.');
if (p != NULL)
*p = '\0';
// Make it lowercase.
for (p = argv[0]; *p != '\0'; ++p)
if (*p >= 'A' && *p <= 'Z')
*p = *p - 'A' + 'a';
#endif
progname = argv[0];
return;
}

32
deps/lzma/common/tuklib_progname.h vendored Normal file
View File

@@ -0,0 +1,32 @@
///////////////////////////////////////////////////////////////////////////////
//
/// \file tuklib_progname.h
/// \brief Program name to be displayed in messages
//
// Author: Lasse Collin
//
// This file has been put into the public domain.
// You can do whatever you want with this file.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef TUKLIB_PROGNAME_H
#define TUKLIB_PROGNAME_H
#include "tuklib_common.h"
#include <errno.h>
TUKLIB_DECLS_BEGIN
#if HAVE_DECL_PROGRAM_INVOCATION_NAME
# define progname program_invocation_name
#else
# define progname TUKLIB_SYMBOL(tuklib_progname)
extern char *progname;
#endif
#define tuklib_progname_init TUKLIB_SYMBOL(tuklib_progname_init)
extern void tuklib_progname_init(char **argv);
TUKLIB_DECLS_END
#endif