# ZEX C API
## License
The C ABI (`libzexc`, `include/zexc.h`) is part of **zexc** and is licensed under
**GPL-3.0-only** (GNU General Public License v3 **only**). See [`../LICENSE`](../LICENSE).
Applications that **link** against `libzexc` (shared or static) are typically
subject to the same copyleft terms when distributed.
## Build
```bash
cargo build --release --features c-api
# Linux: target/release/libzexc.so + libzexc.a
# macOS: target/release/libzexc.dylib
# Windows: target/release/zex.dll + zex.lib
```
Header: [`include/zexc.h`](../include/zexc.h).
## Minimal example
```c
#include "zexc.h"
#include <stdio.h>
int main(void) {
const uint8_t src[] = "hello";
uint8_t *out = NULL;
size_t out_len = 0;
if (zex_compress(src, 5, &out, &out_len, 3, ZEX_MODE_BALANCED) != ZEX_OK)
return 1;
uint8_t *plain = NULL;
size_t plain_len = 0;
if (zex_decompress(out, out_len, &plain, &plain_len) != ZEX_OK)
return 1;
zex_free(out, out_len);
zex_free(plain, plain_len);
return 0;
}
```
Link:
```bash
cc app.c -I include -L target/release -lzexc -lpthread -ldl -lm
```
## Functions
| `zex_version` | Static version string |
| `zex_compress` | Full-frame compress |
| `zex_decompress` | Full-frame decompress |
| `zex_compress_bound` | Conservative size hint |
| `zex_decompress_into` | Decode into caller buffer |
| `zex_free(ptr, len)` | Free library allocations |
## Notes
- Buffers from `zex_compress` / `zex_decompress` must be freed with **`zex_free(p, len)`** (length required).
- Dictionary and encryption are not yet exposed in the C API (Rust API only).
- Threading: C API uses single-thread compress by default for predictability.