From f4603994a39431c8cee036216a6d15ab7281b0c6 Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 14 Dec 2015 01:58:21 -0500 Subject: initial commit. --- src/driver/sfrt_unit_ctx.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/driver/sfrt_unit_ctx.c (limited to 'src/driver/sfrt_unit_ctx.c') diff --git a/src/driver/sfrt_unit_ctx.c b/src/driver/sfrt_unit_ctx.c new file mode 100644 index 0000000..cef9913 --- /dev/null +++ b/src/driver/sfrt_unit_ctx.c @@ -0,0 +1,56 @@ +#include +#include +#include +#include +#include + +#include +#include "sofort_driver_impl.h" + +static int sfrt_free_unit_ctx_impl(struct sfrt_unit_ctx_impl * ctx, int status) +{ + if (ctx) { + sfrt_unmap_input(&ctx->map); + free(ctx); + } + + return status; +} + +int sfrt_get_unit_ctx( + const struct sfrt_driver_ctx * dctx, + const char * path, + struct sfrt_unit_ctx ** pctx) +{ + struct sfrt_unit_ctx_impl * ctx; + + if (!dctx || !(ctx = calloc(sizeof(*ctx),1))) + return -1; + + if (sfrt_map_input(-1,path,PROT_READ,&ctx->map)) + return sfrt_free_unit_ctx_impl(ctx,-1); + + memcpy(&ctx->cctx,dctx->cctx, + sizeof(ctx->cctx)); + + ctx->path = path; + + ctx->uctx.path = &ctx->path; + ctx->uctx.map = &ctx->map; + ctx->uctx.cctx = &ctx->cctx; + + *pctx = &ctx->uctx; + return 0; +} + +void sfrt_free_unit_ctx(struct sfrt_unit_ctx * ctx) +{ + struct sfrt_unit_ctx_impl * ictx; + uintptr_t addr; + + if (ctx) { + addr = (uintptr_t)ctx - offsetof(struct sfrt_unit_ctx_impl,uctx); + ictx = (struct sfrt_unit_ctx_impl *)addr; + sfrt_free_unit_ctx_impl(ictx,0); + } +} -- cgit v1.2.3