diff options
author | midipix <writeonce@midipix.org> | 2015-12-18 02:47:38 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2015-12-18 02:54:25 -0500 |
commit | b1b6990bf565905018ccfe8edb64d1fca50f8fde (patch) | |
tree | 8b4355d544b5e67ab8c10c179a382ac33a987ef6 /src | |
parent | b46bd6be5f9e5e4548e2113415e801d1fa5666fc (diff) | |
download | sofort-b1b6990bf565905018ccfe8edb64d1fca50f8fde.tar.bz2 sofort-b1b6990bf565905018ccfe8edb64d1fca50f8fde.tar.xz |
driver: improve common context initialization logic.
Diffstat (limited to 'src')
-rw-r--r-- | src/driver/sfrt_driver_ctx.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/driver/sfrt_driver_ctx.c b/src/driver/sfrt_driver_ctx.c index 58ea3ce..7a9f81c 100644 --- a/src/driver/sfrt_driver_ctx.c +++ b/src/driver/sfrt_driver_ctx.c @@ -51,7 +51,10 @@ static int sfrt_driver_usage( return SFRT_USAGE; } -static struct sfrt_driver_ctx_impl * sfrt_driver_ctx_alloc(struct argv_meta * meta, size_t nunits) +static struct sfrt_driver_ctx_impl * sfrt_driver_ctx_alloc( + struct argv_meta * meta, + const struct sfrt_common_ctx * cctx, + size_t nunits) { struct sfrt_driver_ctx_alloc * ictx; size_t size; @@ -64,6 +67,9 @@ static struct sfrt_driver_ctx_impl * sfrt_driver_ctx_alloc(struct argv_meta * me if (!(ictx = calloc(size,1))) return 0; + if (cctx) + memcpy(&ictx->ctx.cctx,cctx,sizeof(*cctx)); + for (entry=meta->entries,units=ictx->units; entry->fopt || entry->arg; entry++) if (!entry->fopt) *units++ = entry->arg; @@ -131,13 +137,12 @@ int sfrt_get_driver_ctx( nunits++; } - if (!(ctx = sfrt_driver_ctx_alloc(meta,nunits))) + if (!(ctx = sfrt_driver_ctx_alloc(meta,&cctx,nunits))) return sfrt_get_driver_ctx_fail(meta); ctx->ctx.program = program; ctx->ctx.cctx = &ctx->cctx; - memcpy(&ctx->cctx,&cctx,sizeof(cctx)); *pctx = &ctx->ctx; return SFRT_OK; } @@ -153,7 +158,7 @@ int sfrt_create_driver_ctx( if (!(meta = argv_get(argv,sfrt_default_options,0))) return -1; - if (!(ctx = sfrt_driver_ctx_alloc(meta,0))) + if (!(ctx = sfrt_driver_ctx_alloc(meta,cctx,0))) return sfrt_get_driver_ctx_fail(0); ctx->ctx.cctx = &ctx->cctx; |