From 8ecaec4c703ea8feae104b8301dd0095cb9c1cae Mon Sep 17 00:00:00 2001 From: Steve Lhomme Date: Sun, 3 May 2020 09:38:01 +0200 Subject: [PATCH] Add a C wrapper for decompression --- CMakeLists.txt | 2 ++ lzokay-c/CMakeLists.txt | 5 +++++ lzokay-c/lzokay-c.cpp | 20 ++++++++++++++++++++ lzokay-c/lzokay-c.h | 27 +++++++++++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 lzokay-c/CMakeLists.txt create mode 100644 lzokay-c/lzokay-c.cpp create mode 100644 lzokay-c/lzokay-c.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c6cfd8a..989326d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,3 +52,5 @@ install( FILES "${config_file}" "${version_config_file}" DESTINATION ${config_install_dir} ) + +add_subdirectory("lzokay-c") diff --git a/lzokay-c/CMakeLists.txt b/lzokay-c/CMakeLists.txt new file mode 100644 index 0000000..d0f7c2c --- /dev/null +++ b/lzokay-c/CMakeLists.txt @@ -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) diff --git a/lzokay-c/lzokay-c.cpp b/lzokay-c/lzokay-c.cpp new file mode 100644 index 0000000..0a79c5a --- /dev/null +++ b/lzokay-c/lzokay-c.cpp @@ -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); +} diff --git a/lzokay-c/lzokay-c.h b/lzokay-c/lzokay-c.h new file mode 100644 index 0000000..faa9a3d --- /dev/null +++ b/lzokay-c/lzokay-c.h @@ -0,0 +1,27 @@ +#ifndef LZOKAY_C_INCLUDED +#define LZOKAY_C_INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include + +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