diff options
author | midipix <writeonce@midipix.org> | 2025-05-30 09:29:13 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2025-05-30 13:43:19 +0000 |
commit | 118b747bc6e01eee24f9d205ef7344e497243dd9 (patch) | |
tree | 2399295af41b32bd0918272e8b2d12b63f7dee08 | |
parent | 906422a560cdbf078793143a30274a5faed37d6b (diff) | |
download | perk-118b747bc6e01eee24f9d205ef7344e497243dd9.tar.bz2 perk-118b747bc6e01eee24f9d205ef7344e497243dd9.tar.xz |
library api: _lib_ (program driver) namespace overhaul.
-rw-r--r-- | include/perk/perk.h | 13 | ||||
-rw-r--r-- | src/cmds/pe_cmd_perk.c | 4 | ||||
-rw-r--r-- | src/driver/pe_amain.c | 4 | ||||
-rw-r--r-- | src/driver/pe_driver_ctx.c | 16 | ||||
-rw-r--r-- | src/driver/pe_unit_ctx.c | 12 | ||||
-rw-r--r-- | src/internal/perk_driver_impl.h | 12 |
6 files changed, 31 insertions, 30 deletions
diff --git a/include/perk/perk.h b/include/perk/perk.h index 78f1a0f..06c22b1 100644 --- a/include/perk/perk.h +++ b/include/perk/perk.h @@ -234,19 +234,20 @@ struct pe_info_string { }; /* driver api */ -perk_api int pe_get_driver_ctx (char ** argv, char ** envp, uint32_t flags, +perk_api int pe_lib_get_driver_ctx (char ** argv, char ** envp, uint32_t flags, const struct pe_fd_ctx *, struct pe_driver_ctx **); -perk_api void pe_free_driver_ctx (struct pe_driver_ctx *); +perk_api void pe_lib_free_driver_ctx (struct pe_driver_ctx *); -perk_api int pe_get_unit_ctx (const struct pe_driver_ctx *, const char * path, +perk_api int pe_lib_get_unit_ctx (const struct pe_driver_ctx *, const char * path, struct pe_unit_ctx **); -perk_api void pe_free_unit_ctx (struct pe_unit_ctx *); +perk_api void pe_lib_free_unit_ctx (struct pe_unit_ctx *); -perk_api int pe_get_driver_fdctx (const struct pe_driver_ctx *, struct pe_fd_ctx *); -perk_api int pe_set_driver_fdctx (struct pe_driver_ctx *, const struct pe_fd_ctx *); +perk_api int pe_lib_get_driver_fdctx (const struct pe_driver_ctx *, struct pe_fd_ctx *); + +perk_api int pe_lib_set_driver_fdctx (struct pe_driver_ctx *, const struct pe_fd_ctx *); /* cmd api */ perk_api int pe_cmd_perk (const struct pe_driver_ctx *, const char *); diff --git a/src/cmds/pe_cmd_perk.c b/src/cmds/pe_cmd_perk.c index d2b11a2..0ae6656 100644 --- a/src/cmds/pe_cmd_perk.c +++ b/src/cmds/pe_cmd_perk.c @@ -73,11 +73,11 @@ int pe_cmd_perk(const struct pe_driver_ctx * dctx, const char * path) int ret; struct pe_unit_ctx * uctx; - if ((ret = pe_get_unit_ctx(dctx,path,&uctx)) < 0) + if ((ret = pe_lib_get_unit_ctx(dctx,path,&uctx)) < 0) return ret; pe_perform_unit_actions(dctx,uctx); - pe_free_unit_ctx(uctx); + pe_lib_free_unit_ctx(uctx); return 0; } diff --git a/src/driver/pe_amain.c b/src/driver/pe_amain.c index 8a5724a..173f391 100644 --- a/src/driver/pe_amain.c +++ b/src/driver/pe_amain.c @@ -51,7 +51,7 @@ static ssize_t pe_version(struct pe_driver_ctx * dctx, int fdout) static int pe_exit(struct pe_driver_ctx * dctx, int ret) { pe_output_error_vector(dctx); - pe_free_driver_ctx(dctx); + pe_lib_free_driver_ctx(dctx); return ret; } @@ -66,7 +66,7 @@ int pe_main(char ** argv, char ** envp, const struct pe_fd_ctx * fdctx) flags = PERK_DRIVER_FLAGS; fdout = fdctx ? fdctx->fdout : STDOUT_FILENO; - if ((ret = pe_get_driver_ctx(argv,envp,flags,fdctx,&dctx))) + if ((ret = pe_lib_get_driver_ctx(argv,envp,flags,fdctx,&dctx))) return (ret == PERK_USAGE) ? !argv || !argv[0] || !argv[1] : PERK_ERROR; diff --git a/src/driver/pe_driver_ctx.c b/src/driver/pe_driver_ctx.c index c7cd146..afa46e7 100644 --- a/src/driver/pe_driver_ctx.c +++ b/src/driver/pe_driver_ctx.c @@ -295,13 +295,13 @@ static int pe_cctx_update( return 0; } -static int pe_get_driver_ctx_fail(struct argv_meta * meta) +static int pe_lib_get_driver_ctx_fail(struct argv_meta * meta) { argv_free(meta); return -1; } -int pe_get_driver_ctx( +int pe_lib_get_driver_ctx( char ** argv, char ** envp, uint32_t flags, @@ -443,7 +443,7 @@ int pe_get_driver_ctx( /* context allocation */ if (!(ctx = pe_driver_ctx_alloc(meta,fdctx,&cctx,nunits))) - return pe_get_driver_ctx_fail(meta); + return pe_lib_get_driver_ctx_fail(meta); ctx->ctx.program = program; ctx->ctx.cctx = &ctx->cctx; @@ -452,13 +452,13 @@ int pe_get_driver_ctx( return PERK_OK; } -static void pe_free_driver_ctx_impl(struct pe_driver_ctx_alloc * ictx) +static void pe_lib_free_driver_ctx_impl(struct pe_driver_ctx_alloc * ictx) { argv_free(ictx->meta); free(ictx); } -void pe_free_driver_ctx(struct pe_driver_ctx * ctx) +void pe_lib_free_driver_ctx(struct pe_driver_ctx * ctx) { struct pe_driver_ctx_alloc * ictx; uintptr_t addr; @@ -467,7 +467,7 @@ void pe_free_driver_ctx(struct pe_driver_ctx * ctx) addr = (uintptr_t)ctx - offsetof(struct pe_driver_ctx_impl,ctx); addr = addr - offsetof(struct pe_driver_ctx_alloc,ctx); ictx = (struct pe_driver_ctx_alloc *)addr; - pe_free_driver_ctx_impl(ictx); + pe_lib_free_driver_ctx_impl(ictx); } } @@ -476,7 +476,7 @@ const struct pe_source_version * pe_source_version(void) return &pe_src_version; } -int pe_get_driver_fdctx( +int pe_lib_get_driver_fdctx( const struct pe_driver_ctx * dctx, struct pe_fd_ctx * fdctx) { @@ -494,7 +494,7 @@ int pe_get_driver_fdctx( return 0; } -int pe_set_driver_fdctx( +int pe_lib_set_driver_fdctx( struct pe_driver_ctx * dctx, const struct pe_fd_ctx * fdctx) { diff --git a/src/driver/pe_unit_ctx.c b/src/driver/pe_unit_ctx.c index 5333a2d..48afa81 100644 --- a/src/driver/pe_unit_ctx.c +++ b/src/driver/pe_unit_ctx.c @@ -14,7 +14,7 @@ #include "perk_driver_impl.h" #include "perk_errinfo_impl.h" -static int pe_free_unit_ctx_impl(struct pe_unit_ctx_impl * ctx, int ret) +static int pe_lib_free_unit_ctx_impl(struct pe_unit_ctx_impl * ctx, int ret) { if (ctx) { pe_free_image_meta(ctx->meta); @@ -25,7 +25,7 @@ static int pe_free_unit_ctx_impl(struct pe_unit_ctx_impl * ctx, int ret) return ret; } -int pe_get_unit_ctx( +int pe_lib_get_unit_ctx( const struct pe_driver_ctx * dctx, const char * path, struct pe_unit_ctx ** pctx) @@ -48,11 +48,11 @@ int pe_get_unit_ctx( : PROT_READ; if (pe_map_raw_image(dctx,-1,path,prot,&ctx->map)) - return pe_free_unit_ctx_impl(ctx, + return pe_lib_free_unit_ctx_impl(ctx, PERK_NESTED_ERROR(dctx)); if (pe_get_image_meta(dctx,&ctx->map,&ctx->meta)) - return pe_free_unit_ctx_impl(ctx, + return pe_lib_free_unit_ctx_impl(ctx, PERK_NESTED_ERROR(dctx)); ctx->path = path; @@ -64,7 +64,7 @@ int pe_get_unit_ctx( return 0; } -void pe_free_unit_ctx(struct pe_unit_ctx * ctx) +void pe_lib_free_unit_ctx(struct pe_unit_ctx * ctx) { struct pe_unit_ctx_impl * ictx; uintptr_t addr; @@ -72,6 +72,6 @@ void pe_free_unit_ctx(struct pe_unit_ctx * ctx) if (ctx) { addr = (uintptr_t)ctx - offsetof(struct pe_unit_ctx_impl,uctx); ictx = (struct pe_unit_ctx_impl *)addr; - pe_free_unit_ctx_impl(ictx,0); + pe_lib_free_unit_ctx_impl(ictx,0); } } diff --git a/src/internal/perk_driver_impl.h b/src/internal/perk_driver_impl.h index 46fed8b..e50d08a 100644 --- a/src/internal/perk_driver_impl.h +++ b/src/internal/perk_driver_impl.h @@ -80,42 +80,42 @@ static inline void pe_driver_set_ectx( static inline int pe_driver_fdin(const struct pe_driver_ctx * dctx) { struct pe_fd_ctx fdctx; - pe_get_driver_fdctx(dctx,&fdctx); + pe_lib_get_driver_fdctx(dctx,&fdctx); return fdctx.fdin; } static inline int pe_driver_fdout(const struct pe_driver_ctx * dctx) { struct pe_fd_ctx fdctx; - pe_get_driver_fdctx(dctx,&fdctx); + pe_lib_get_driver_fdctx(dctx,&fdctx); return fdctx.fdout; } static inline int pe_driver_fderr(const struct pe_driver_ctx * dctx) { struct pe_fd_ctx fdctx; - pe_get_driver_fdctx(dctx,&fdctx); + pe_lib_get_driver_fdctx(dctx,&fdctx); return fdctx.fderr; } static inline int pe_driver_fdlog(const struct pe_driver_ctx * dctx) { struct pe_fd_ctx fdctx; - pe_get_driver_fdctx(dctx,&fdctx); + pe_lib_get_driver_fdctx(dctx,&fdctx); return fdctx.fdlog; } static inline int pe_driver_fdcwd(const struct pe_driver_ctx * dctx) { struct pe_fd_ctx fdctx; - pe_get_driver_fdctx(dctx,&fdctx); + pe_lib_get_driver_fdctx(dctx,&fdctx); return fdctx.fdcwd; } static inline int pe_driver_fddst(const struct pe_driver_ctx * dctx) { struct pe_fd_ctx fdctx; - pe_get_driver_fdctx(dctx,&fdctx); + pe_lib_get_driver_fdctx(dctx,&fdctx); return fdctx.fddst; } |