Apache OpenDAL™ C Binding
The C binding for Apache OpenDAL™
Loading...
Searching...
No Matches
Apache OpenDAL™ C Binding (WIP)

A C binding for OpenDAL, providing blocking access to S3, GCS, Azure Blob, the local filesystem, and 50+ more storage backends through a single C API.

Note: This binding has its own independent version number, which may differ from the Rust core version.

User guide: https://opendal.apache.org/docs/bindings/c

Building

Requirements: C11/C++14 compiler, CMake, Rust toolchain.

mkdir -p build && cd build
# Default build (memory + fs services)
cmake ..
make
# Enable additional services
cmake .. -DFEATURES="opendal/services-s3,opendal/services-gcs"
make

The header is at include/opendal.h. The shared library is written to ../../target/debug/ after building.

Example

#include <assert.h>
#include <stdio.h>
#include "opendal.h"
int main(void)
{
/* Build an operator for the "memory" service. */
assert(result.op != NULL && result.error == NULL);
opendal_operator *op = result.op;
/* Write bytes. */
const char *msg = "Hello, OpenDAL!";
opendal_bytes data = { .data = (uint8_t *)msg, .len = 15 };
opendal_error *err = opendal_operator_write(op, "/hello.txt", &data);
assert(err == NULL);
/* Read them back. */
assert(r.error == NULL);
printf("%.*s\n", (int)r.data.len, r.data.data);
return 0;
}
struct opendal_error * opendal_operator_write(const struct opendal_operator *op, const char *path, const struct opendal_bytes *bytes)
Blocking write raw bytes to path.
void opendal_operator_free(const struct opendal_operator *ptr)
Free the heap-allocated operator pointed by opendal_operator.
struct opendal_result_operator_new opendal_operator_new(const char *scheme, const struct opendal_operator_options *options)
Construct an operator based on scheme and options
struct opendal_result_read opendal_operator_read(const struct opendal_operator *op, const char *path)
Blocking read the data from path.
void opendal_bytes_free(struct opendal_bytes *ptr)
Frees the heap memory used by the opendal_bytes.
opendal_bytes carries raw-bytes with its length
Definition opendal.h:101
uintptr_t len
Definition opendal.h:109
uint8_t * data
Definition opendal.h:105
The opendal error type for C binding, containing an error code and corresponding error message.
Definition opendal.h:135
Used to access almost all OpenDAL APIs. It represents an operator that provides the unified interface...
Definition opendal.h:261
The result type returned by opendal_operator_new() operation.
Definition opendal.h:281
struct opendal_operator * op
Definition opendal.h:285
struct opendal_error * error
Definition opendal.h:289
The result type returned by opendal's read operation.
Definition opendal.h:393
struct opendal_bytes data
Definition opendal.h:397
struct opendal_error * error
Definition opendal.h:401

See examples/ for more, including error handling patterns.

Full documentation is at https://opendal.apache.org/docs/bindings/c.

Contributing

See `CONTRIBUTING.md` at the repository root. To run tests you need Valgrind and GTest:

cd build && make tests && ./tests

Format C sources with make format (requires clang-format). Do not manually format include/opendal.h.

License and Trademarks

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

Apache OpenDAL, OpenDAL, and Apache are either registered trademarks or trademarks of the Apache Software Foundation.