From 0ca708eae20ba675458c29124f771c8f29dd12a7 Mon Sep 17 00:00:00 2001 From: Naoto Yamaguchi Date: Mon, 4 Jul 2022 07:31:03 +0900 Subject: Add example code Bug-AGL: SPEC-4500 Signed-off-by: Naoto Yamaguchi Change-Id: I3e90808ef0ec37fdac79cbe9c33fe68f339608c4 --- example/example.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 example/example.c diff --git a/example/example.c b/example/example.c new file mode 100644 index 0000000..69d19c0 --- /dev/null +++ b/example/example.c @@ -0,0 +1,86 @@ +/** + * SPDX-License-Identifier: Apache-2.0 + * + * @file example.c + * @brief example for librefop + */ + +#include "librefop.h" + +#include +#include +#include +#include +#include + + +//int mkdir(const char *pathname, mode_t mode); + +const char filedir[] = "/tmp/refop-test/"; +const char filename[] = "refop-example.bin"; + +int main(int argc, char *argv[]) +{ + refop_handle_t handle; + refop_error_t ret = REFOP_SUCCESS; + uint8_t *pbuf = NULL; + int64_t sz = 128 * 1024; + int64_t szr = 0; + + // Data directry need to make self. + mkdir(filedir, 0777); + + // Create handle + ret = refop_create_redundancy_handle(&handle, filedir, filename); + if (ret != REFOP_SUCCESS) { + fprintf(stderr, "Fail to create refop handle: return %d\n", (int) ret); + return -1; + } + + // Example data create + pbuf = (uint8_t *) malloc(sz); + if (pbuf == NULL) { + fprintf(stderr, "Malloc fail\n"); + return -1; + } + memset(pbuf, 0xff, sz); + + // Set data + ret = refop_set_redundancy_data(handle, pbuf, sz); + if (ret != REFOP_SUCCESS) { + fprintf(stderr, "Fail to set data: return %d\n", (int) ret); + return -1; + } + + // Set data + ret = refop_set_redundancy_data(handle, pbuf, sz); + if (ret != REFOP_SUCCESS) { + fprintf(stderr, "Fail to set data: return %d\n", (int) ret); + return -1; + } + + // Set data + ret = refop_set_redundancy_data(handle, pbuf, sz); + if (ret != REFOP_SUCCESS) { + fprintf(stderr, "Fail to set data: return %d\n", (int) ret); + return -1; + } + + // Get data + ret = refop_get_redundancy_data(handle, pbuf, sz, &szr); + if (ret != REFOP_SUCCESS) { + fprintf(stderr, "Fail to get data: return %d\n", (int) ret); + return -1; + } + + ret = refop_remove_redundancy_data(handle); + if (ret != REFOP_SUCCESS) { + fprintf(stderr, "Fail to remove data: return %d\n", (int) ret); + return -1; + } + + // Release handle + (void) refop_release_redundancy_handle(handle); + + return 0; +} -- cgit 1.2.3-korg