2013-09-28 17:43:30 +01:00
|
|
|
/*
|
|
|
|
* Private includes and definitions for userspace use of XZ Embedded
|
|
|
|
*
|
|
|
|
* Author: Lasse Collin <lasse.collin@tukaani.org>
|
|
|
|
*
|
|
|
|
* This file has been put into the public domain.
|
|
|
|
* You can do whatever you want with this file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef XZ_CONFIG_H
|
|
|
|
#define XZ_CONFIG_H
|
|
|
|
|
|
|
|
/* Uncomment to enable CRC64 support. */
|
|
|
|
/* #define XZ_USE_CRC64 */
|
|
|
|
|
|
|
|
/* Uncomment as needed to enable BCJ filter decoders. */
|
|
|
|
/* #define XZ_DEC_X86 */
|
|
|
|
/* #define XZ_DEC_POWERPC */
|
|
|
|
/* #define XZ_DEC_IA64 */
|
|
|
|
/* #define XZ_DEC_ARM */
|
|
|
|
/* #define XZ_DEC_ARMTHUMB */
|
|
|
|
/* #define XZ_DEC_SPARC */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MSVC doesn't support modern C but XZ Embedded is mostly C89
|
|
|
|
* so these are enough.
|
|
|
|
*/
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
typedef unsigned char bool;
|
2013-11-04 01:53:05 +00:00
|
|
|
#define true 1
|
|
|
|
#define false 0
|
|
|
|
#define inline __inline
|
2013-09-28 17:43:30 +01:00
|
|
|
#else
|
2013-11-04 01:53:05 +00:00
|
|
|
#include <stdbool.h>
|
2013-09-28 17:43:30 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "xz.h"
|
|
|
|
|
|
|
|
#define kmalloc(size, flags) malloc(size)
|
|
|
|
#define kfree(ptr) free(ptr)
|
|
|
|
#define vmalloc(size) malloc(size)
|
|
|
|
#define vfree(ptr) free(ptr)
|
|
|
|
|
|
|
|
#define memeq(a, b, size) (memcmp(a, b, size) == 0)
|
|
|
|
#define memzero(buf, size) memset(buf, 0, size)
|
|
|
|
|
|
|
|
#ifndef min
|
2013-11-04 01:53:05 +00:00
|
|
|
#define min(x, y) ((x) < (y) ? (x) : (y))
|
2013-09-28 17:43:30 +01:00
|
|
|
#endif
|
|
|
|
#define min_t(type, x, y) min(x, y)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some functions have been marked with __always_inline to keep the
|
|
|
|
* performance reasonable even when the compiler is optimizing for
|
|
|
|
* small code size. You may be able to save a few bytes by #defining
|
|
|
|
* __always_inline to plain inline, but don't complain if the code
|
|
|
|
* becomes slow.
|
|
|
|
*
|
|
|
|
* NOTE: System headers on GNU/Linux may #define this macro already,
|
|
|
|
* so if you want to change it, you need to #undef it first.
|
|
|
|
*/
|
|
|
|
#ifndef __always_inline
|
2013-11-04 01:53:05 +00:00
|
|
|
#ifdef __GNUC__
|
|
|
|
#define __always_inline inline __attribute__((__always_inline__))
|
|
|
|
#else
|
|
|
|
#define __always_inline inline
|
|
|
|
#endif
|
2013-09-28 17:43:30 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Inline functions to access unaligned unsigned 32-bit integers */
|
|
|
|
#ifndef get_unaligned_le32
|
|
|
|
static inline uint32_t get_unaligned_le32(const uint8_t *buf)
|
|
|
|
{
|
2013-11-04 01:53:05 +00:00
|
|
|
return (uint32_t)buf[0] | ((uint32_t)buf[1] << 8) | ((uint32_t)buf[2] << 16) |
|
|
|
|
((uint32_t)buf[3] << 24);
|
2013-09-28 17:43:30 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef get_unaligned_be32
|
|
|
|
static inline uint32_t get_unaligned_be32(const uint8_t *buf)
|
|
|
|
{
|
2013-11-04 01:53:05 +00:00
|
|
|
return (uint32_t)(buf[0] << 24) | ((uint32_t)buf[1] << 16) | ((uint32_t)buf[2] << 8) |
|
|
|
|
(uint32_t)buf[3];
|
2013-09-28 17:43:30 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef put_unaligned_le32
|
|
|
|
static inline void put_unaligned_le32(uint32_t val, uint8_t *buf)
|
|
|
|
{
|
|
|
|
buf[0] = (uint8_t)val;
|
|
|
|
buf[1] = (uint8_t)(val >> 8);
|
|
|
|
buf[2] = (uint8_t)(val >> 16);
|
|
|
|
buf[3] = (uint8_t)(val >> 24);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef put_unaligned_be32
|
|
|
|
static inline void put_unaligned_be32(uint32_t val, uint8_t *buf)
|
|
|
|
{
|
|
|
|
buf[0] = (uint8_t)(val >> 24);
|
|
|
|
buf[1] = (uint8_t)(val >> 16);
|
|
|
|
buf[2] = (uint8_t)(val >> 8);
|
|
|
|
buf[3] = (uint8_t)val;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use get_unaligned_le32() also for aligned access for simplicity. On
|
|
|
|
* little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr))
|
|
|
|
* could save a few bytes in code size.
|
|
|
|
*/
|
|
|
|
#ifndef get_le32
|
2013-11-04 01:53:05 +00:00
|
|
|
#define get_le32 get_unaligned_le32
|
2013-09-28 17:43:30 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|