mirror of
https://github.com/cuberite/libdeflate.git
synced 2025-09-07 19:26:29 -04:00

Allow building libdeflate without linking to any libc functions by using 'make FREESTANDING=1'. When using such a library build, the user will need to call libdeflate_set_memory_allocator() before anything else, since malloc() and free() will be unavailable. [Folded in fix from Ingvar Stepanyan to use -nostdlib, and made freestanding_tests() check that no libs are linked to.] Update https://github.com/ebiggers/libdeflate/issues/62
49 lines
1.6 KiB
C
49 lines
1.6 KiB
C
/*
|
|
* lib_common.h - internal header included by all library code
|
|
*/
|
|
|
|
#ifndef LIB_LIB_COMMON_H
|
|
#define LIB_LIB_COMMON_H
|
|
|
|
#ifdef LIBDEFLATE_H
|
|
# error "lib_common.h must always be included before libdeflate.h"
|
|
/* because BUILDING_LIBDEFLATE must be set first */
|
|
#endif
|
|
|
|
#define BUILDING_LIBDEFLATE
|
|
|
|
#include "common_defs.h"
|
|
|
|
/*
|
|
* Prefix with "_libdeflate_" all global symbols which are not part of the API
|
|
* and don't already have a "libdeflate" prefix. This avoids exposing overly
|
|
* generic names when libdeflate is built as a static library.
|
|
*
|
|
* Note that the chosen prefix is not really important and can be changed
|
|
* without breaking library users. It was just chosen so that the resulting
|
|
* symbol names are unlikely to conflict with those from any other software.
|
|
* Also note that this fixup has no useful effect when libdeflate is built as a
|
|
* shared library, since these symbols are not exported.
|
|
*/
|
|
#define SYM_FIXUP(sym) _libdeflate_##sym
|
|
#define deflate_get_compression_level SYM_FIXUP(deflate_get_compression_level)
|
|
#define _cpu_features SYM_FIXUP(_cpu_features)
|
|
#define setup_cpu_features SYM_FIXUP(setup_cpu_features)
|
|
|
|
void *libdeflate_malloc(size_t size);
|
|
void libdeflate_free(void *ptr);
|
|
|
|
void *libdeflate_aligned_malloc(size_t alignment, size_t size);
|
|
void libdeflate_aligned_free(void *ptr);
|
|
|
|
#ifdef FREESTANDING
|
|
void *memset(void *s, int c, size_t n);
|
|
void *memcpy(void *dest, const void *src, size_t n);
|
|
void *memmove(void *dest, const void *src, size_t n);
|
|
int memcmp(const void *s1, const void *s2, size_t n);
|
|
#else
|
|
#include <string.h>
|
|
#endif
|
|
|
|
#endif /* LIB_LIB_COMMON_H */
|