diff options
-rw-r--r-- | include/perk/perk.h | 14 | ||||
-rw-r--r-- | src/driver/pe_driver_ctx.c | 23 | ||||
-rw-r--r-- | src/driver/pe_unit_ctx.c | 4 | ||||
-rw-r--r-- | src/internal/perk_impl.h | 2 | ||||
-rw-r--r-- | src/internal/perk_output_impl.h | 4 | ||||
-rw-r--r-- | src/perk.c | 8 |
6 files changed, 30 insertions, 25 deletions
diff --git a/include/perk/perk.h b/include/perk/perk.h index 0b84349..459fffb 100644 --- a/include/perk/perk.h +++ b/include/perk/perk.h @@ -100,7 +100,10 @@ struct pe_server_ctx { const char ** attrs; }; -struct pe_common_ctx { +struct pe_io_ctx { + int status; + int prot; + int mode; int fdin; int fdout; int fderr; @@ -108,11 +111,9 @@ struct pe_common_ctx { int fdsrc; int fddst; int fdtmp; - int prot; - int mode; - int status; - ssize_t ioread; - ssize_t iowrite; +}; + +struct pe_common_ctx { uint64_t drvflags; uint64_t actflags; uint64_t fmtflags; @@ -125,6 +126,7 @@ struct pe_common_ctx { const struct pe_output_ctx * outctx; const struct pe_linker_ctx * lnkctx; const struct pe_server_ctx * srvctx; + const struct pe_io_ctx * ioctx; }; struct pe_driver_ctx { diff --git a/src/driver/pe_driver_ctx.c b/src/driver/pe_driver_ctx.c index 9f9dd88..e3e9cdb 100644 --- a/src/driver/pe_driver_ctx.c +++ b/src/driver/pe_driver_ctx.c @@ -105,6 +105,7 @@ static struct pe_driver_ctx_impl * pe_driver_ctx_alloc(struct argv_meta * meta, ictx->ctx.cctx.outctx = &ictx->outctx; ictx->ctx.cctx.lnkctx = &ictx->lnkctx; ictx->ctx.cctx.srvctx = &ictx->srvctx; + ictx->ctx.cctx.ioctx = &ictx->ctx.ioctx; for (entry=meta->entries,units=ictx->units; entry->fopt || entry->arg; entry++) if (!entry->fopt) @@ -205,14 +206,14 @@ int pe_get_driver_ctx( ctx->cctx.drvflags = dflags; ctx->cctx.fmtflags = fflags; ctx->cctx.output = output; - ctx->cctx.fdout = output ? fdout : -1; + ctx->ioctx.fdout = output ? fdout : -1; - ctx->cctx.fdin = -1; - ctx->cctx.fderr = -1; - ctx->cctx.fdlog = -1; - ctx->cctx.fdsrc = AT_FDCWD; - ctx->cctx.fddst = AT_FDCWD; - ctx->cctx.fdtmp = AT_FDCWD; + ctx->ioctx.fdin = -1; + ctx->ioctx.fderr = -1; + ctx->ioctx.fdlog = -1; + ctx->ioctx.fdsrc = AT_FDCWD; + ctx->ioctx.fddst = AT_FDCWD; + ctx->ioctx.fdtmp = AT_FDCWD; ctx->ctx.cctx = &ctx->cctx; @@ -222,11 +223,11 @@ int pe_get_driver_ctx( static void pe_driver_close_fds(struct pe_common_ctx * cctx) { - if (cctx->status && cctx->output) - unlinkat(cctx->fddst,cctx->output,0); + if (cctx->ioctx->status && cctx->output) + unlinkat(cctx->ioctx->fddst,cctx->output,0); - if (cctx->fdout >= 0) - close(cctx->fdout); + if (cctx->ioctx->fdout >= 0) + close(cctx->ioctx->fdout); } static void pe_free_driver_ctx_impl(struct pe_driver_ctx_alloc * ictx) diff --git a/src/driver/pe_unit_ctx.c b/src/driver/pe_unit_ctx.c index df5409b..40e88ab 100644 --- a/src/driver/pe_unit_ctx.c +++ b/src/driver/pe_unit_ctx.c @@ -33,7 +33,7 @@ int pe_get_unit_ctx( ? PROT_READ | PROT_WRITE : PROT_READ; - if (pe_map_raw_image(dctx->cctx->fdin,path,prot,&ctx->map)) + if (pe_map_raw_image(dctx->cctx->ioctx->fdin,path,prot,&ctx->map)) return pe_free_unit_ctx_impl(ctx,-1); if (pe_get_image_meta(&ctx->map,&ctx->meta)) @@ -43,7 +43,7 @@ int pe_get_unit_ctx( sizeof(ctx->cctx)); ctx->path = ctx->path; - ctx->cctx.prot = prot; + ctx->ioctx.prot = prot; ctx->uctx.path = &ctx->path; ctx->uctx.map = &ctx->map; diff --git a/src/internal/perk_impl.h b/src/internal/perk_impl.h index 77a64ae..7cfc590 100644 --- a/src/internal/perk_impl.h +++ b/src/internal/perk_impl.h @@ -9,6 +9,7 @@ #include <perk/perk_meta.h> struct pe_driver_ctx_impl { + struct pe_io_ctx ioctx; struct pe_common_ctx cctx; struct pe_driver_ctx ctx; }; @@ -17,6 +18,7 @@ struct pe_unit_ctx_impl { const char * path; struct pe_raw_image map; struct pe_image_meta * meta; + struct pe_io_ctx ioctx; struct pe_common_ctx cctx; struct pe_unit_ctx uctx; }; diff --git a/src/internal/perk_output_impl.h b/src/internal/perk_output_impl.h index d6f328a..62f0322 100644 --- a/src/internal/perk_output_impl.h +++ b/src/internal/perk_output_impl.h @@ -14,10 +14,10 @@ static inline FILE * pe_output_prolog( return fout; else if (!cctx) return 0; - else if (cctx->fdout < 0) + else if (cctx->ioctx->fdout < 0) return stdout; - if ((fdout = dup(cctx->fdout)) < 0) + if ((fdout = dup(cctx->ioctx->fdout)) < 0) return 0; if ((*ftmp = fdopen(fdout,"a"))) @@ -15,9 +15,9 @@ static ssize_t perk_version(struct pe_driver_ctx * dctx) char buf[512]; size_t len; - if (dctx->cctx->fdout >= 0) { + if (dctx->cctx->ioctx->fdout >= 0) { len = sprintf(buf,vermsg,dctx->program,PERK_GIT_VERSION); - return write(dctx->cctx->fdout,buf,len); + return write(dctx->cctx->ioctx->fdout,buf,len); } else return fprintf(stdout,vermsg,dctx->program,PERK_GIT_VERSION); } @@ -27,8 +27,8 @@ static ssize_t perk_paragraph_break(struct pe_unit_ctx * uctx, int * fpara) if (*fpara) { *fpara = 0; - if (uctx->cctx->fdout >= 0) - return write(uctx->cctx->fdout,"\n",1); + if (uctx->cctx->ioctx->fdout >= 0) + return write(uctx->cctx->ioctx->fdout,"\n",1); else return fputc('\n',stdout); } else |