diff options
author | Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp> | 2022-07-04 07:31:03 +0900 |
---|---|---|
committer | Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp> | 2022-08-02 01:01:26 +0900 |
commit | 0ca708eae20ba675458c29124f771c8f29dd12a7 (patch) | |
tree | a49b4388ee8f254980af27f38d2c77182f590027 | |
parent | 9eb9bf0460b2bba954452126bc02cf74aeb731cd (diff) |
Add example code
Bug-AGL: SPEC-4500
Signed-off-by: Naoto Yamaguchi <naoto.yamaguchi@aisin.co.jp>
Change-Id: I3e90808ef0ec37fdac79cbe9c33fe68f339608c4
-rw-r--r-- | example/example.c | 86 |
1 files changed, 86 insertions, 0 deletions
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 <stdio.h> +#include <sys/stat.h> +#include <sys/types.h> +#include <string.h> +#include <stdlib.h> + + +//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; +} |