summaryrefslogtreecommitdiff
path: root/src/driver/tpax_unit_ctx.c
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2020-01-27 08:36:51 -0500
committermidipix <writeonce@midipix.org>2020-05-23 05:59:01 +0000
commit88751e9e5ee3726b8a6987aeaae04e956c2234f5 (patch)
tree1ba3549be38e7a9348ad5b48bb35869e3e733daa /src/driver/tpax_unit_ctx.c
parentfa6b3e3522edcd8c202669c5587f2b5c77ac150d (diff)
downloadtpax-88751e9e5ee3726b8a6987aeaae04e956c2234f5.tar.bz2
tpax-88751e9e5ee3726b8a6987aeaae04e956c2234f5.tar.xz
created lib-app skeleton (foss21.org lib-app model).
Diffstat (limited to 'src/driver/tpax_unit_ctx.c')
-rw-r--r--src/driver/tpax_unit_ctx.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/driver/tpax_unit_ctx.c b/src/driver/tpax_unit_ctx.c
new file mode 100644
index 0000000..a6a91b6
--- /dev/null
+++ b/src/driver/tpax_unit_ctx.c
@@ -0,0 +1,61 @@
+/******************************************************/
+/* tpax: a topological pax implementation */
+/* Copyright (C) 2020 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.TPAX. */
+/******************************************************/
+
+#include <stdint.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+
+#include <tpax/tpax.h>
+#include "tpax_driver_impl.h"
+#include "tpax_errinfo_impl.h"
+
+static int tpax_free_unit_ctx_impl(struct tpax_unit_ctx_impl * ctx, int ret)
+{
+ if (ctx) {
+ free(ctx);
+ }
+
+ return ret;
+}
+
+int tpax_get_unit_ctx(
+ const struct tpax_driver_ctx * dctx,
+ const char * path,
+ struct tpax_unit_ctx ** pctx)
+{
+ struct tpax_unit_ctx_impl * ctx;
+
+ if (!dctx)
+ return TPAX_CUSTOM_ERROR(
+ dctx,TPAX_ERR_NULL_CONTEXT);
+
+ else if (!(ctx = calloc(1,sizeof(*ctx))))
+ return TPAX_BUFFER_ERROR(dctx);
+
+ tpax_driver_set_ectx(
+ dctx,0,path);
+
+ ctx->path = path;
+ ctx->uctx.path = &ctx->path;
+
+ *pctx = &ctx->uctx;
+
+ return 0;
+}
+
+void tpax_free_unit_ctx(struct tpax_unit_ctx * ctx)
+{
+ struct tpax_unit_ctx_impl * ictx;
+ uintptr_t addr;
+
+ if (ctx) {
+ addr = (uintptr_t)ctx - offsetof(struct tpax_unit_ctx_impl,uctx);
+ ictx = (struct tpax_unit_ctx_impl *)addr;
+ tpax_free_unit_ctx_impl(ictx,0);
+ }
+}