blob: 586cd6ff9f92967e799736e930832b0c90d6e9d6 [file] [log] [blame]
/* Copyright (c) 2016 Google Inc. All rights reserved.
*
* This file defines kernel specific macros used by the Linux kernel's xz
* library.
*
* Description from xz_private.h:
* For userspace builds, use a separate header to define the required
* macros and functions. This makes it easier to adapt the code into
* different environments and avoids clutter in the Linux kernel tree.
*/
#ifndef XZ_CONFIG_H
#define XZ_CONFIG_H
#include <stdbool.h>
#include <stddef.h>
#include <string.h>
#include <stdlib.h>
#include "xz.h"
#define INIT /* empty */
#define memmove memmove
#define kmalloc(size, flags) malloc(size)
#define kfree(ptr) free(ptr)
#define vmalloc(size) malloc(size)
#define vfree(ptr) do { if (ptr != NULL) free(ptr); } while (0)
#define get_le32(p) (*(uint32_t*)(p))
#define min(x, y) ({ \
typeof(x) _min1 = (x); \
typeof(y) _min2 = (y); \
(void) (&_min1 == &_min2); \
_min1 < _min2 ? _min1 : _min2; })
#define max(x, y) ({ \
typeof(x) _max1 = (x); \
typeof(y) _max2 = (y); \
(void) (&_max1 == &_max2); \
_max1 > _max2 ? _max1 : _max2; })
#define min_t(type, x, y) ({ \
type __min1 = (x); \
type __min2 = (y); \
__min1 < __min2 ? __min1: __min2; })
#define max_t(type, x, y) ({ \
type __max1 = (x); \
type __max2 = (y); \
__max1 > __max2 ? __max1: __max2; })
#endif // XZ_CONFIG_H