Add a C wrapper for decompression

This commit is contained in:
Steve Lhomme 2020-05-03 09:38:01 +02:00
parent 671e2b9864
commit 8ecaec4c70
4 changed files with 54 additions and 0 deletions

View File

@ -52,3 +52,5 @@ install(
FILES "${config_file}" "${version_config_file}"
DESTINATION ${config_install_dir}
)
add_subdirectory("lzokay-c")

5
lzokay-c/CMakeLists.txt Normal file
View File

@ -0,0 +1,5 @@
project(lzokay-c VERSION 0.1 LANGUAGES C CXX)
add_library(lzokay-c lzokay-c.cpp lzokay-c.h)
target_link_libraries(lzokay-c PRIVATE lzokay)
set_target_properties(lzokay-c PROPERTIES CXX_STANDARD 14)

20
lzokay-c/lzokay-c.cpp Normal file
View File

@ -0,0 +1,20 @@
#include "lzokay-c.h"
#include "../lzokay.hpp"
static_assert(EResult_LookbehindOverrun == lzokay_EResult(lzokay::EResult::LookbehindOverrun), "LookbehindOverrun mismatch");
static_assert(EResult_OutputOverrun == lzokay_EResult(lzokay::EResult::OutputOverrun), "OutputOverrun mismatch");
static_assert(EResult_InputOverrun == lzokay_EResult(lzokay::EResult::InputOverrun), "InputOverrun mismatch");
static_assert(EResult_Error == lzokay_EResult(lzokay::EResult::Error), "Error mismatch");
static_assert(EResult_Success == lzokay_EResult(lzokay::EResult::Success), "Success mismatch");
static_assert(EResult_InputNotConsumed == lzokay_EResult(lzokay::EResult::InputNotConsumed), "InputNotConsumed mismatch");
extern "C"
lzokay_EResult lzokay_decompress(const uint8_t * src, size_t src_size,
uint8_t *output, size_t *output_len)
{
size_t needed_size = 0;
lzokay::EResult error =
lzokay::decompress(src, src_size, output, *output_len, needed_size);
*output_len = needed_size;
return lzokay_EResult(error);
}

27
lzokay-c/lzokay-c.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef LZOKAY_C_INCLUDED
#define LZOKAY_C_INCLUDED
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stddef.h>
typedef enum {
EResult_LookbehindOverrun = -4,
EResult_OutputOverrun = -3,
EResult_InputOverrun = -2,
EResult_Error = -1,
EResult_Success = 0,
EResult_InputNotConsumed = 1,
} lzokay_EResult;
lzokay_EResult lzokay_decompress(const uint8_t * src, size_t src_size,
uint8_t *output, size_t *output_len);
#ifdef __cplusplus
}
#endif
#endif // LZOKAY_C_INCLUDED