From a313a4648ed153a53296f1e6b1bcda83b3c9f4da Mon Sep 17 00:00:00 2001 From: midipix Date: Tue, 19 Apr 2016 12:08:51 -0400 Subject: driver: added slbt_set_alternate_host(), slbt_reset_alternate_host(). --- src/driver/slbt_driver_ctx.c | 55 +++++++++++++++++++++++++++++++++++++ src/internal/slibtool_driver_impl.h | 1 + 2 files changed, 56 insertions(+) (limited to 'src') diff --git a/src/driver/slbt_driver_ctx.c b/src/driver/slbt_driver_ctx.c index eac0ac6..68ddee8 100644 --- a/src/driver/slbt_driver_ctx.c +++ b/src/driver/slbt_driver_ctx.c @@ -441,6 +441,8 @@ static void slbt_free_host_params(struct slbt_host_strs * host) if (host->dlltool) free(host->dlltool); + + memset(host,0,sizeof(*host)); } static void slbt_init_flavor_settings( @@ -909,3 +911,56 @@ void slbt_free_driver_ctx(struct slbt_driver_ctx * ctx) slbt_free_driver_ctx_impl(ictx); } } + +void slbt_reset_alternate_host(const struct slbt_driver_ctx * ctx) +{ + struct slbt_driver_ctx_alloc * ictx; + uintptr_t addr; + + addr = (uintptr_t)ctx - offsetof(struct slbt_driver_ctx_alloc,ctx); + addr = addr - offsetof(struct slbt_driver_ctx_impl,ctx); + ictx = (struct slbt_driver_ctx_alloc *)addr; + + slbt_free_host_params(&ictx->ctx.ahost); +} + +int slbt_set_alternate_host( + const struct slbt_driver_ctx * ctx, + const char * host, + const char * flavor) +{ + struct slbt_driver_ctx_alloc * ictx; + uintptr_t addr; + + addr = (uintptr_t)ctx - offsetof(struct slbt_driver_ctx_alloc,ctx); + addr = addr - offsetof(struct slbt_driver_ctx_impl,ctx); + ictx = (struct slbt_driver_ctx_alloc *)addr; + slbt_free_host_params(&ictx->ctx.ahost); + + if (!(ictx->ctx.ahost.host = strdup(host))) + return -1; + + if (!(ictx->ctx.ahost.flavor = strdup(flavor))) { + slbt_free_host_params(&ictx->ctx.ahost); + return -1; + } + + ictx->ctx.cctx.ahost.host = ictx->ctx.ahost.host; + ictx->ctx.cctx.ahost.flavor = ictx->ctx.ahost.flavor; + + if (slbt_init_host_params( + ctx->cctx, + &ictx->ctx.ahost, + &ictx->ctx.cctx.ahost, + &ictx->ctx.cctx.acfgmeta)) { + slbt_free_host_params(&ictx->ctx.ahost); + return -1; + } + + slbt_init_flavor_settings( + &ictx->ctx.cctx, + &ictx->ctx.cctx.ahost, + &ictx->ctx.cctx.asettings); + + return 0; +} diff --git a/src/internal/slibtool_driver_impl.h b/src/internal/slibtool_driver_impl.h index 466a4b3..b7a089f 100644 --- a/src/internal/slibtool_driver_impl.h +++ b/src/internal/slibtool_driver_impl.h @@ -64,6 +64,7 @@ struct slbt_driver_ctx_impl { struct slbt_common_ctx cctx; struct slbt_driver_ctx ctx; struct slbt_host_strs host; + struct slbt_host_strs ahost; char * libname; char ** targv; char ** cargv; -- cgit v1.2.3