Path: blob/main/sys/contrib/xz-embedded/userspace/xz_config.h
48254 views
/*1* Private includes and definitions for userspace use of XZ Embedded2*3* Author: Lasse Collin <[email protected]>4*5* This file has been put into the public domain.6* You can do whatever you want with this file.7*/89#ifndef XZ_CONFIG_H10#define XZ_CONFIG_H1112/* Uncomment to enable building of xz_dec_catrun(). */13/* #define XZ_DEC_CONCATENATED */1415/* Uncomment to enable CRC64 support. */16/* #define XZ_USE_CRC64 */1718/* Uncomment as needed to enable BCJ filter decoders. */19/* #define XZ_DEC_X86 */20/* #define XZ_DEC_POWERPC */21/* #define XZ_DEC_IA64 */22/* #define XZ_DEC_ARM */23/* #define XZ_DEC_ARMTHUMB */24/* #define XZ_DEC_SPARC */2526/*27* MSVC doesn't support modern C but XZ Embedded is mostly C8928* so these are enough.29*/30#ifdef _MSC_VER31typedef unsigned char bool;32# define true 133# define false 034# define inline __inline35#else36# include <stdbool.h>37#endif3839#include <stdlib.h>40#include <string.h>4142#include "xz.h"4344#define kmalloc(size, flags) malloc(size)45#define kfree(ptr) free(ptr)46#define vmalloc(size) malloc(size)47#define vfree(ptr) free(ptr)4849#define memeq(a, b, size) (memcmp(a, b, size) == 0)50#define memzero(buf, size) memset(buf, 0, size)5152#ifndef min53# define min(x, y) ((x) < (y) ? (x) : (y))54#endif55#define min_t(type, x, y) min(x, y)5657/*58* Some functions have been marked with __always_inline to keep the59* performance reasonable even when the compiler is optimizing for60* small code size. You may be able to save a few bytes by #defining61* __always_inline to plain inline, but don't complain if the code62* becomes slow.63*64* NOTE: System headers on GNU/Linux may #define this macro already,65* so if you want to change it, you need to #undef it first.66*/67#ifndef __always_inline68# ifdef __GNUC__69# define __always_inline \70inline __attribute__((__always_inline__))71# else72# define __always_inline inline73# endif74#endif7576/* Inline functions to access unaligned unsigned 32-bit integers */77#ifndef get_unaligned_le3278static inline uint32_t get_unaligned_le32(const uint8_t *buf)79{80return (uint32_t)buf[0]81| ((uint32_t)buf[1] << 8)82| ((uint32_t)buf[2] << 16)83| ((uint32_t)buf[3] << 24);84}85#endif8687#ifndef get_unaligned_be3288static inline uint32_t get_unaligned_be32(const uint8_t *buf)89{90return (uint32_t)(buf[0] << 24)91| ((uint32_t)buf[1] << 16)92| ((uint32_t)buf[2] << 8)93| (uint32_t)buf[3];94}95#endif9697#ifndef put_unaligned_le3298static inline void put_unaligned_le32(uint32_t val, uint8_t *buf)99{100buf[0] = (uint8_t)val;101buf[1] = (uint8_t)(val >> 8);102buf[2] = (uint8_t)(val >> 16);103buf[3] = (uint8_t)(val >> 24);104}105#endif106107#ifndef put_unaligned_be32108static inline void put_unaligned_be32(uint32_t val, uint8_t *buf)109{110buf[0] = (uint8_t)(val >> 24);111buf[1] = (uint8_t)(val >> 16);112buf[2] = (uint8_t)(val >> 8);113buf[3] = (uint8_t)val;114}115#endif116117/*118* Use get_unaligned_le32() also for aligned access for simplicity. On119* little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr))120* could save a few bytes in code size.121*/122#ifndef get_le32123# define get_le32 get_unaligned_le32124#endif125126#endif127128129