diff options
author | midipix <writeonce@midipix.org> | 2018-06-27 03:51:35 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2018-06-27 07:30:01 -0400 |
commit | a82cc2f34bddae9b79e582a3bcc6b2c9cbb5009b (patch) | |
tree | 1d0de0094b350cf323b6ea8ee44f571918048789 | |
parent | 6088476d902b8bcbf688ce7cb6055a4c47c2d0b7 (diff) | |
download | slibtool-a82cc2f34bddae9b79e582a3bcc6b2c9cbb5009b.tar.bz2 slibtool-a82cc2f34bddae9b79e582a3bcc6b2c9cbb5009b.tar.xz |
driver, library interfaces: support alternate fd's for input/output/error/log.
-rw-r--r-- | include/slibtool/slibtool.h | 19 | ||||
-rw-r--r-- | src/driver/slbt_amain.c | 25 | ||||
-rw-r--r-- | src/driver/slbt_driver_ctx.c | 117 | ||||
-rw-r--r-- | src/internal/slibtool_driver_impl.h | 29 | ||||
-rw-r--r-- | src/logic/slbt_exec_install.c | 15 | ||||
-rw-r--r-- | src/logic/slbt_exec_uninstall.c | 20 | ||||
-rw-r--r-- | src/output/slbt_output_config.c | 31 | ||||
-rw-r--r-- | src/output/slbt_output_error.c | 22 | ||||
-rw-r--r-- | src/output/slbt_output_exec.c | 33 | ||||
-rw-r--r-- | src/output/slbt_output_features.c | 15 | ||||
-rw-r--r-- | src/slibtool.c | 2 |
11 files changed, 236 insertions, 92 deletions
diff --git a/include/slibtool/slibtool.h b/include/slibtool/slibtool.h index c34bf99..54b3e4d 100644 --- a/include/slibtool/slibtool.h +++ b/include/slibtool/slibtool.h @@ -122,6 +122,13 @@ struct slbt_source_version { const char * commit; }; +struct slbt_fd_ctx { + int fdin; + int fdout; + int fderr; + int fdlog; +}; + struct slbt_exec_ctx { char * program; char * compiler; @@ -247,10 +254,15 @@ struct slbt_driver_ctx { slbt_api const struct slbt_source_version * slbt_source_version(void); /* driver api */ -slbt_api int slbt_get_driver_ctx (char ** argv, char ** envp, uint32_t flags, struct slbt_driver_ctx **); -slbt_api int slbt_create_driver_ctx (const struct slbt_common_ctx *, struct slbt_driver_ctx **); +slbt_api int slbt_get_driver_ctx (char ** argv, char ** envp, uint32_t flags, + const struct slbt_fd_ctx *, struct slbt_driver_ctx **); +slbt_api int slbt_create_driver_ctx (const struct slbt_common_ctx *, + const struct slbt_fd_ctx *, struct slbt_driver_ctx **); slbt_api void slbt_free_driver_ctx (struct slbt_driver_ctx *); +slbt_api int slbt_get_driver_fdctx (const struct slbt_driver_ctx *, struct slbt_fd_ctx *); +slbt_api int slbt_set_driver_fdctx (struct slbt_driver_ctx *, const struct slbt_fd_ctx *); + /* execution context api */ slbt_api int slbt_get_exec_ctx (const struct slbt_driver_ctx *, struct slbt_exec_ctx **); slbt_api void slbt_free_exec_ctx (struct slbt_exec_ctx *); @@ -276,7 +288,8 @@ slbt_api int slbt_copy_file (const struct slbt_driver_ctx *, struct slbt_exec_ slbt_api int slbt_dump_machine (const char * compiler, char * machine, size_t bufsize); /* utility api */ -slbt_api int slbt_main (int, char **, char **); +slbt_api int slbt_main (int, char **, char **, + const struct slbt_fd_ctx *); slbt_api int slbt_output_config (const struct slbt_driver_ctx *); slbt_api int slbt_output_features (const struct slbt_driver_ctx *); slbt_api int slbt_output_exec (const struct slbt_driver_ctx *, const struct slbt_exec_ctx *, const char *); diff --git a/src/driver/slbt_amain.c b/src/driver/slbt_amain.c index 7d4a5a9..73e698e 100644 --- a/src/driver/slbt_amain.c +++ b/src/driver/slbt_amain.c @@ -10,6 +10,7 @@ #include <errno.h> #include <slibtool/slibtool.h> #include "slibtool_driver_impl.h" +#include "slibtool_dprintf_impl.h" #ifndef SLBT_DRIVER_FLAGS #define SLBT_DRIVER_FLAGS SLBT_DRIVER_VERBOSITY_ERRORS \ @@ -32,17 +33,17 @@ static const char * const slbt_ver_plain[6] = { "","" }; -static ssize_t slbt_version(struct slbt_driver_ctx * dctx) +static ssize_t slbt_version(int fdout, struct slbt_driver_ctx * dctx) { const struct slbt_source_version * verinfo; const char * const * verclr; bool gitver; verinfo = slbt_source_version(); - verclr = isatty(STDOUT_FILENO) ? slbt_ver_color : slbt_ver_plain; + verclr = isatty(fdout) ? slbt_ver_color : slbt_ver_plain; gitver = strcmp(verinfo->commit,"unknown"); - return fprintf(stdout,vermsg, + return slbt_dprintf(fdout,vermsg, verclr[0],dctx->program,verclr[1], verclr[2],verinfo->major,verinfo->minor, verinfo->revision,verclr[3], @@ -82,15 +83,20 @@ static int slbt_exit(struct slbt_driver_ctx * dctx, int ret) return ret; } -int slbt_main(int argc, char ** argv, char ** envp) +int slbt_main(int argc, char ** argv, char ** envp, + const struct slbt_fd_ctx * fdctx) { int ret; + int fdout; uint64_t flags; struct slbt_driver_ctx * dctx; char * program; char * dash; char * sargv[5]; + flags = SLBT_DRIVER_FLAGS; + fdout = fdctx ? fdctx->fdout : STDOUT_FILENO; + /* --version only? */ if ((argc == 2) && (!strcmp(argv[1],"--version") || !strcmp(argv[1],"--help-all") @@ -102,8 +108,8 @@ int slbt_main(int argc, char ** argv, char ** envp) sargv[3] = "<compiler>"; sargv[4] = 0; - return (slbt_get_driver_ctx(sargv,envp,SLBT_DRIVER_FLAGS,&dctx)) - ? SLBT_ERROR : (slbt_version(dctx) < 0) + return (slbt_get_driver_ctx(sargv,envp,flags,fdctx,&dctx)) + ? SLBT_ERROR : (slbt_version(fdout,dctx) < 0) ? slbt_exit(dctx,SLBT_ERROR) : slbt_exit(dctx,SLBT_OK); } @@ -128,9 +134,6 @@ int slbt_main(int argc, char ** argv, char ** envp) else if (!(strcmp(dash,"static"))) flags = SLBT_DRIVER_FLAGS | SLBT_DRIVER_DISABLE_SHARED; - else - flags = SLBT_DRIVER_FLAGS; - /* debug */ if (!(strcmp(program,"dlibtool"))) flags |= SLBT_DRIVER_DEBUG; @@ -148,13 +151,13 @@ int slbt_main(int argc, char ** argv, char ** envp) flags |= SLBT_DRIVER_LEGABITS; /* driver context */ - if ((ret = slbt_get_driver_ctx(argv,envp,flags,&dctx))) + if ((ret = slbt_get_driver_ctx(argv,envp,flags,fdctx,&dctx))) return (ret == SLBT_USAGE) ? !--argc : SLBT_ERROR; if (dctx->cctx->drvflags & SLBT_DRIVER_VERSION) - if ((slbt_version(dctx)) < 0) + if ((slbt_version(fdout,dctx)) < 0) return slbt_exit(dctx,SLBT_ERROR); slbt_perform_driver_actions(dctx); diff --git a/src/driver/slbt_driver_ctx.c b/src/driver/slbt_driver_ctx.c index adce17d..151363f 100644 --- a/src/driver/slbt_driver_ctx.c +++ b/src/driver/slbt_driver_ctx.c @@ -79,7 +79,7 @@ struct slbt_driver_ctx_alloc { uint64_t guard; }; -static void slbt_output_raw_vector(char ** argv, char ** envp) +static void slbt_output_raw_vector(int fderr, char ** argv, char ** envp) { char ** parg; char * dot; @@ -88,10 +88,10 @@ static void slbt_output_raw_vector(char ** argv, char ** envp) (void)envp; - if ((fcolor = isatty(STDERR_FILENO))) - fprintf(stderr,"%s%s",aclr_bold,aclr_red); + if ((fcolor = isatty(fderr))) + slbt_dprintf(fderr,"%s%s",aclr_bold,aclr_red); - fprintf(stderr,"\n\n\n%s",argv[0]); + slbt_dprintf(fderr,"\n\n\n%s",argv[0]); for (parg=&argv[1]; *parg; parg++) { if (!fcolor) @@ -107,10 +107,10 @@ static void slbt_output_raw_vector(char ** argv, char ** envp) else color = aclr_white; - fprintf(stderr," %s%s",color,*parg); + slbt_dprintf(fderr," %s%s",color,*parg); } - fprintf(stderr,"%s\n\n",fcolor ? aclr_reset : ""); + slbt_dprintf(fderr,"%s\n\n",fcolor ? aclr_reset : ""); } static uint32_t slbt_argv_flags(uint32_t flags) @@ -130,6 +130,7 @@ static uint32_t slbt_argv_flags(uint32_t flags) } static int slbt_driver_usage( + int fdout, const char * program, const char * arg, const struct argv_option ** optv, @@ -141,7 +142,7 @@ static int slbt_driver_usage( "Usage: %s [options] <file>...\n" "Options:\n", program); - argv_usage(STDOUT_FILENO,header,optv,arg); + argv_usage(fdout,header,optv,arg); argv_free(meta); return SLBT_USAGE; @@ -149,6 +150,7 @@ static int slbt_driver_usage( static struct slbt_driver_ctx_impl * slbt_driver_ctx_alloc( struct argv_meta * meta, + const struct slbt_fd_ctx * fdctx, const struct slbt_common_ctx * cctx) { struct slbt_driver_ctx_alloc * ictx; @@ -160,8 +162,8 @@ static struct slbt_driver_ctx_impl * slbt_driver_ctx_alloc( if (!(ictx = calloc(1,size))) return 0; - if (cctx) - memcpy(&ictx->ctx.cctx,cctx,sizeof(*cctx)); + memcpy(&ictx->ctx.fdctx,fdctx,sizeof(*fdctx)); + memcpy(&ictx->ctx.cctx,cctx,sizeof(*cctx)); elements = sizeof(ictx->ctx.erribuf) / sizeof(*ictx->ctx.erribuf); @@ -182,7 +184,8 @@ static int slbt_get_driver_ctx_fail(struct argv_meta * meta) static int slbt_split_argv( char ** argv, uint32_t flags, - struct slbt_split_vector * sargv) + struct slbt_split_vector * sargv, + int fderr) { int i; int argc; @@ -209,7 +212,9 @@ static int slbt_split_argv( argv_optv_init(slbt_default_options,optv); if (!argv[1] && (flags & SLBT_DRIVER_VERBOSITY_USAGE)) - return slbt_driver_usage(program,0,optv,0); + return slbt_driver_usage( + fderr,program, + 0,optv,0); /* initial argv scan: ... --mode=xxx ... <compiler> ... */ argv_scan(argv,optv,&ctx,0); @@ -220,7 +225,7 @@ static int slbt_split_argv( argv_get( argv,optv, slbt_argv_flags(flags), - STDERR_FILENO); + fderr); return -1; } @@ -229,10 +234,10 @@ static int slbt_split_argv( compiler = argv[ctx.unitidx]; argv[ctx.unitidx] = 0; - meta = argv_get(argv,optv,ARGV_VERBOSITY_NONE,STDERR_FILENO); + meta = argv_get(argv,optv,ARGV_VERBOSITY_NONE,fderr); argv[ctx.unitidx] = compiler; } else { - meta = argv_get(argv,optv,ARGV_VERBOSITY_NONE,STDERR_FILENO); + meta = argv_get(argv,optv,ARGV_VERBOSITY_NONE,fderr); } /* missing all of --mode, --config, --features, and --finish? */ @@ -251,7 +256,7 @@ static int slbt_split_argv( argv_free(meta); if (!mode && !config && !finish && !features) { - fprintf(stderr, + slbt_dprintf(fderr, "%s: error: --mode must be specified.\n", program); return -1; @@ -260,7 +265,7 @@ static int slbt_split_argv( /* missing compiler? */ if (!ctx.unitidx && !finish && !features) { if (flags & SLBT_DRIVER_VERBOSITY_ERRORS) - fprintf(stderr, + slbt_dprintf(fderr, "%s: error: <compiler> is missing.\n", program); return -1; @@ -773,7 +778,7 @@ static int slbt_init_version_info( if (current < age) { if (ictx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) - fprintf(stderr, + slbt_dprintf(ictx->fdctx.fderr, "%s: error: invalid version info: " "<current> may not be smaller than <age>.\n", argv_program_name(ictx->cctx.targv[0])); @@ -795,7 +800,9 @@ static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx) const char * base; char * dot; bool fmodule; + int fderr; + fderr = ctx->fdctx.fderr; program = argv_program_name(ctx->cctx.targv[0]); libname = 0; prefix = 0; @@ -804,7 +811,7 @@ static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx) /* output */ if (!(ctx->cctx.output)) { if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) - fprintf(stderr, + slbt_dprintf(fderr, "%s: error: output file must be " "specified in link mode.\n", program); @@ -829,7 +836,7 @@ static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx) libname = base; else { if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) - fprintf(stderr, + slbt_dprintf(fderr, "%s: error: output file prefix does " "not match its (archive) suffix; " "the expected prefix was '%s'\n", @@ -846,7 +853,7 @@ static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx) libname = base; else { if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) - fprintf(stderr, + slbt_dprintf(fderr, "%s: error: output file prefix does " "not match its (shared library) suffix; " "the expected prefix was '%s'\n", @@ -867,7 +874,7 @@ static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx) fmodule = true; } else { if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS) - fprintf(stderr, + slbt_dprintf(fderr, "%s: error: output file prefix does " "not match its (libtool wrapper) suffix; " "the expected prefix was '%s'\n", @@ -896,6 +903,7 @@ int slbt_get_driver_ctx( char ** argv, char ** envp, uint32_t flags, + const struct slbt_fd_ctx * fdctx, struct slbt_driver_ctx ** pctx) { struct slbt_split_vector sargv; @@ -908,13 +916,22 @@ int slbt_get_driver_ctx( argv_optv_init(slbt_default_options,optv); - if (slbt_split_argv(argv,flags,&sargv)) + if (!fdctx) { + fdctx = &(const struct slbt_fd_ctx) { + .fdin = STDIN_FILENO, + .fdout = STDOUT_FILENO, + .fderr = STDERR_FILENO, + .fdlog = (-1) + }; + } + + if (slbt_split_argv(argv,flags,&sargv,fdctx->fderr)) return -1; if (!(meta = argv_get( sargv.targv,optv, slbt_argv_flags(flags), - STDERR_FILENO))) + fdctx->fderr))) return -1; program = argv_program_name(argv[0]); @@ -933,7 +950,9 @@ int slbt_get_driver_ctx( case TAG_HELP: case TAG_HELP_ALL: if (flags & SLBT_DRIVER_VERBOSITY_USAGE) - return slbt_driver_usage(program,entry->arg,optv,meta); + return slbt_driver_usage( + fdctx->fdout,program, + entry->arg,optv,meta); case TAG_VERSION: cctx.drvflags |= SLBT_DRIVER_VERSION; @@ -1184,7 +1203,7 @@ int slbt_get_driver_ctx( /* debug: raw argument vector */ if (cctx.drvflags & SLBT_DRIVER_DEBUG) - slbt_output_raw_vector(argv,envp); + slbt_output_raw_vector(fdctx->fderr,argv,envp); /* -o in install mode means USER */ if ((cctx.mode == SLBT_MODE_INSTALL) && cctx.output) { @@ -1197,7 +1216,7 @@ int slbt_get_driver_ctx( cctx.mode = SLBT_MODE_INFO; /* driver context */ - if (!(ctx = slbt_driver_ctx_alloc(meta,&cctx))) + if (!(ctx = slbt_driver_ctx_alloc(meta,fdctx,&cctx))) return slbt_get_driver_ctx_fail(meta); ctx->ctx.program = program; @@ -1252,6 +1271,7 @@ int slbt_get_driver_ctx( int slbt_create_driver_ctx( const struct slbt_common_ctx * cctx, + const struct slbt_fd_ctx * fdctx, struct slbt_driver_ctx ** pctx) { const struct argv_option * optv[SLBT_OPTV_ELEMENTS]; @@ -1261,10 +1281,19 @@ int slbt_create_driver_ctx( argv_optv_init(slbt_default_options,optv); - if (!(meta = argv_get(argv,optv,0,STDERR_FILENO))) + if (!fdctx) { + fdctx = &(const struct slbt_fd_ctx) { + .fdin = STDIN_FILENO, + .fdout = STDOUT_FILENO, + .fderr = STDERR_FILENO, + .fdlog = (-1) + }; + } + + if (!(meta = argv_get(argv,optv,0,fdctx->fderr))) return -1; - if (!(ctx = slbt_driver_ctx_alloc(meta,cctx))) + if (!(ctx = slbt_driver_ctx_alloc(meta,fdctx,cctx))) return slbt_get_driver_ctx_fail(0); ctx->ctx.cctx = &ctx->cctx; @@ -1364,3 +1393,35 @@ const struct slbt_source_version * slbt_source_version(void) { return &slbt_src_version; } + +int slbt_get_driver_fdctx( + const struct slbt_driver_ctx * dctx, + struct slbt_fd_ctx * fdctx) +{ + struct slbt_driver_ctx_impl * ictx; + + ictx = slbt_get_driver_ictx(dctx); + + fdctx->fdin = ictx->fdctx.fdin; + fdctx->fdout = ictx->fdctx.fdout; + fdctx->fderr = ictx->fdctx.fderr; + fdctx->fdlog = ictx->fdctx.fdlog; + + return 0; +} + +int slbt_set_driver_fdctx( + struct slbt_driver_ctx * dctx, + const struct slbt_fd_ctx * fdctx) +{ + struct slbt_driver_ctx_impl * ictx; + + ictx = slbt_get_driver_ictx(dctx); + + ictx->fdctx.fdin = fdctx->fdin; + ictx->fdctx.fdout = fdctx->fdout; + ictx->fdctx.fderr = fdctx->fderr; + ictx->fdctx.fdlog = fdctx->fdlog; + + return 0; +} diff --git a/src/internal/slibtool_driver_impl.h b/src/internal/slibtool_driver_impl.h index 2f2302a..ef67bb8 100644 --- a/src/internal/slibtool_driver_impl.h +++ b/src/internal/slibtool_driver_impl.h @@ -83,6 +83,7 @@ struct slbt_driver_ctx_impl { struct slbt_driver_ctx ctx; struct slbt_host_strs host; struct slbt_host_strs ahost; + struct slbt_fd_ctx fdctx; char * libname; char ** targv; char ** cargv; @@ -104,4 +105,32 @@ static inline struct slbt_driver_ctx_impl * slbt_get_driver_ictx(const struct sl return 0; } +static inline int slbt_driver_fdin(const struct slbt_driver_ctx * dctx) +{ + struct slbt_fd_ctx fdctx; + slbt_get_driver_fdctx(dctx,&fdctx); + return fdctx.fdin; +} + +static inline int slbt_driver_fdout(const struct slbt_driver_ctx * dctx) +{ + struct slbt_fd_ctx fdctx; + slbt_get_driver_fdctx(dctx,&fdctx); + return fdctx.fdout; +} + +static inline int slbt_driver_fderr(const struct slbt_driver_ctx * dctx) +{ + struct slbt_fd_ctx fdctx; + slbt_get_driver_fdctx(dctx,&fdctx); + return fdctx.fderr; +} + +static inline int slbt_driver_fdlog(const struct slbt_driver_ctx * dctx) +{ + struct slbt_fd_ctx fdctx; + slbt_get_driver_fdctx(dctx,&fdctx); + return fdctx.fdlog; +} + #endif diff --git a/src/logic/slbt_exec_install.c b/src/logic/slbt_exec_install.c index c00215a..e15a4b2 100644 --- a/src/logic/slbt_exec_install.c +++ b/src/logic/slbt_exec_install.c @@ -23,6 +23,7 @@ #include "argv/argv.h" static int slbt_install_usage( + int fdout, const char * program, const char * arg, const struct argv_option ** optv, @@ -35,7 +36,7 @@ static int slbt_install_usage( "Options:\n", program); - argv_usage(STDOUT_FILENO,header,optv,arg); + argv_usage(fdout,header,optv,arg); argv_free(meta); return SLBT_USAGE; @@ -536,6 +537,7 @@ int slbt_exec_install( struct slbt_exec_ctx * ectx) { int ret; + int fdout; char ** argv; char ** iargv; char ** src; @@ -565,6 +567,7 @@ int slbt_exec_install( slbt_reset_arguments(ectx); slbt_disable_placeholders(ectx); iargv = ectx->cargv; + fdout = slbt_driver_fdout(dctx); /* work around non-conforming uses of --mode=install */ if (!(strcmp(iargv[0],"/bin/sh")) || !strcmp(iargv[0],"/bin/bash")) @@ -574,16 +577,18 @@ int slbt_exec_install( argv_optv_init(slbt_install_options,optv); if (!iargv[1] && (dctx->cctx->drvflags & SLBT_DRIVER_VERBOSITY_USAGE)) - return slbt_install_usage(dctx->program,0,optv,0); + return slbt_install_usage( + fdout, + dctx->program, + 0,optv,0); /* <install> argv meta */ if (!(meta = argv_get( - iargv, - optv, + iargv,optv, dctx->cctx->drvflags & SLBT_DRIVER_VERBOSITY_ERRORS ? ARGV_VERBOSITY_ERRORS : ARGV_VERBOSITY_NONE, - STDERR_FILENO))) + fdout))) return slbt_exec_install_fail( actx,meta, SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_INSTALL_FAIL)); diff --git a/src/logic/slbt_exec_uninstall.c b/src/logic/slbt_exec_uninstall.c index 1168c7d..b733d27 100644 --- a/src/logic/slbt_exec_uninstall.c +++ b/src/logic/slbt_exec_uninstall.c @@ -21,6 +21,7 @@ #include "argv/argv.h" static int slbt_uninstall_usage( + int fdout, const char * program, const char * arg, const struct argv_option ** optv, @@ -33,7 +34,7 @@ static int slbt_uninstall_usage( "Options:\n", program); - argv_usage(STDOUT_FILENO,header,optv,arg); + argv_usage(fdout,header,optv,arg); argv_free(meta); return SLBT_USAGE; @@ -245,6 +246,7 @@ int slbt_exec_uninstall( struct slbt_exec_ctx * ectx) { int ret; + int fdout; char ** argv; char ** iargv; uint32_t flags; @@ -269,6 +271,7 @@ int slbt_exec_uninstall( slbt_reset_arguments(ectx); slbt_disable_placeholders(ectx); iargv = ectx->cargv; + fdout = slbt_driver_fdout(dctx); /* work around non-conforming uses of --mode=uninstall */ if (!(strcmp(iargv[0],"/bin/sh")) || !strcmp(iargv[0],"/bin/bash")) @@ -278,16 +281,18 @@ int slbt_exec_uninstall( argv_optv_init(slbt_uninstall_options,optv); if (!iargv[1] && (dctx->cctx->drvflags & SLBT_DRIVER_VERBOSITY_USAGE)) - return slbt_uninstall_usage(dctx->program,0,optv,0); + return slbt_uninstall_usage( + fdout, + dctx->program, + 0,optv,0); /* <uninstall> argv meta */ if (!(meta = argv_get( - iargv, - optv, + iargv,optv, dctx->cctx->drvflags & SLBT_DRIVER_VERBOSITY_ERRORS ? ARGV_VERBOSITY_ERRORS : ARGV_VERBOSITY_NONE, - STDERR_FILENO))) + fdout))) return slbt_exec_uninstall_fail( actx,meta, SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_UNINSTALL_FAIL)); @@ -329,7 +334,10 @@ int slbt_exec_uninstall( /* --help */ if (flags & SLBT_UNINSTALL_HELP) { - slbt_uninstall_usage(dctx->program,0,optv,meta); + slbt_uninstall_usage( + fdout, + dctx->program, + 0,optv,meta); return 0; } diff --git a/src/output/slbt_output_config.c b/src/output/slbt_output_config.c index 800c6c3..fc8f5ca 100644 --- a/src/output/slbt_output_config.c +++ b/src/output/slbt_output_config.c @@ -9,6 +9,8 @@ #include <stdbool.h> #include <slibtool/slibtool.h> +#include "slibtool_driver_impl.h" +#include "slibtool_dprintf_impl.h" #include "slibtool_errinfo_impl.h" #ifndef SLBT_TAB_WIDTH @@ -20,12 +22,13 @@ #endif static bool slbt_output_config_line( + int fd, const char * key, const char * value, const char * annotation, int midwidth) { - return (fprintf(stdout,"%-*s%-*s%s\n", + return (slbt_dprintf(fd,"%-*s%-*s%s\n", SLBT_KEY_WIDTH, key, midwidth, value ? value : "", annotation ? annotation : "") < 0) @@ -39,11 +42,13 @@ int slbt_output_config(const struct slbt_driver_ctx * dctx) const char * target; int len; int midwidth; + int fdout; cctx = dctx->cctx; compiler = cctx->cargv[0] ? cctx->cargv[0] : ""; target = cctx->target ? cctx->target : ""; midwidth = strlen(compiler); + fdout = slbt_driver_fdout(dctx); if ((len = strlen(target)) > midwidth) midwidth = len; @@ -69,37 +74,35 @@ int slbt_output_config(const struct slbt_driver_ctx * dctx) midwidth += SLBT_TAB_WIDTH; midwidth &= (~(SLBT_TAB_WIDTH-1)); - if (slbt_output_config_line("key","value","annotation",midwidth)) + if (slbt_output_config_line(fdout,"key","value","annotation",midwidth)) return SLBT_SYSTEM_ERROR(dctx); - if (slbt_output_config_line("---","-----","----------",midwidth)) + if (slbt_output_config_line(fdout,"---","-----","----------",midwidth)) return SLBT_SYSTEM_ERROR(dctx); - if (slbt_output_config_line("compiler",cctx->cargv[0],"",midwidth)) + if (slbt_output_config_line(fdout,"compiler",cctx->cargv[0],"",midwidth)) return SLBT_SYSTEM_ERROR(dctx); - if (slbt_output_config_line("target",cctx->target,"",midwidth)) + if (slbt_output_config_line(fdout,"target",cctx->target,"",midwidth)) return SLBT_SYSTEM_ERROR(dctx); - if (slbt_output_config_line("host",cctx->host.host,cctx->cfgmeta.host,midwidth)) + if (slbt_output_config_line(fdout,"host",cctx->host.host,cctx->cfgmeta.host,midwidth)) return SLBT_SYSTEM_ERROR(dctx); - if (slbt_output_config_line("flavor",cctx->host.flavor,cctx->cfgmeta.flavor,midwidth)) + if (slbt_output_config_line(fdout,"flavor",cctx->host.flavor,cctx->cfgmeta.flavor,midwidth)) return SLBT_SYSTEM_ERROR(dctx); - if (slbt_output_config_line("ar",cctx->host.ar,cctx->cfgmeta.ar,midwidth)) + if (slbt_output_config_line(fdout,"ar",cctx->host.ar,cctx->cfgmeta.ar,midwidth)) return SLBT_SYSTEM_ERROR(dctx); - if (slbt_output_config_line("ranlib",cctx->host.ranlib,cctx->cfgmeta.ranlib,midwidth)) + if (slbt_output_config_line(fdout,"ranlib",cctx->host.ranlib,cctx->cfgmeta.ranlib,midwidth)) return SLBT_SYSTEM_ERROR(dctx); - if (slbt_output_config_line("dlltool",cctx->host.dlltool,cctx->cfgmeta.dlltool,midwidth)) + if (slbt_output_config_line(fdout,"dlltool",cctx->host.dlltool,cctx->cfgmeta.dlltool,midwidth)) return SLBT_SYSTEM_ERROR(dctx); - if (slbt_output_config_line("mdso",cctx->host.mdso,cctx->cfgmeta.mdso,midwidth)) + if (slbt_output_config_line(fdout,"mdso",cctx->host.mdso,cctx->cfgmeta.mdso,midwidth)) return SLBT_SYSTEM_ERROR(dctx); - return fflush(stdout) - ? SLBT_SYSTEM_ERROR(dctx) - : 0; + return 0; } diff --git a/src/output/slbt_output_error.c b/src/output/slbt_output_error.c index 49a27b8..0ccabb2 100644 --- a/src/output/slbt_output_error.c +++ b/src/output/slbt_output_error.c @@ -10,6 +10,9 @@ #include <unistd.h> #include <slibtool/slibtool.h> +#include "slibtool_driver_impl.h" +#include "slibtool_dprintf_impl.h" + static const char aclr_reset[] = "\x1b[0m"; static const char aclr_bold[] = "\x1b[1m"; @@ -56,7 +59,8 @@ static int slbt_output_error_record_plain( { const char * errdesc = slbt_output_strerror(erri); - if (fprintf(stderr,"%s: %s %s(), line %d%s%s.\n", + if (slbt_dprintf(slbt_driver_fderr(dctx), + "%s: %s %s(), line %d%s%s.\n", dctx->program, slbt_output_error_header(erri), erri->efunction, @@ -65,7 +69,7 @@ static int slbt_output_error_record_plain( errdesc) < 0) return -1; - return fflush(stderr); + return 0; } static int slbt_output_error_record_annotated( @@ -74,8 +78,8 @@ static int slbt_output_error_record_annotated( { const char * errdesc = slbt_output_strerror(erri); - if (fprintf( - stderr, + if (slbt_dprintf( + slbt_driver_fderr(dctx), "%s%s%s:%s %s%s%s %s%s%s()%s, %s%sline %d%s%s%s%s%s.\n", aclr_bold,aclr_magenta, @@ -100,20 +104,22 @@ static int slbt_output_error_record_annotated( aclr_reset) < 0) return -1; - return fflush(stderr); + return 0; } int slbt_output_error_record( const struct slbt_driver_ctx * dctx, const struct slbt_error_info * erri) { + int fderr = slbt_driver_fderr(dctx); + if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER) return slbt_output_error_record_plain(dctx,erri); else if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_ALWAYS) return slbt_output_error_record_annotated(dctx,erri); - else if (isatty(STDERR_FILENO)) + else if (isatty(fderr)) return slbt_output_error_record_annotated(dctx,erri); else @@ -144,13 +150,15 @@ static int slbt_output_error_vector_annotated(const struct slbt_driver_ctx * dct int slbt_output_error_vector(const struct slbt_driver_ctx * dctx) { + int fderr = slbt_driver_fderr(dctx); + if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER) return slbt_output_error_vector_plain(dctx); else if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_ALWAYS) return slbt_output_error_vector_annotated(dctx); - else if (isatty(STDERR_FILENO)) + else if (isatty(fderr)) return slbt_output_error_vector_annotated(dctx); else diff --git a/src/output/slbt_output_exec.c b/src/output/slbt_output_exec.c index effa3b7..7d773c2 100644 --- a/src/output/slbt_output_exec.c +++ b/src/output/slbt_output_exec.c @@ -7,6 +7,9 @@ #include <unistd.h> #include <stdio.h> #include <slibtool/slibtool.h> + +#include "slibtool_driver_impl.h" +#include "slibtool_dprintf_impl.h" #include "slibtool_errinfo_impl.h" static const char aclr_null[] = ""; @@ -22,12 +25,16 @@ static int slbt_output_exec_annotated( const struct slbt_exec_ctx * ectx, const char * step) { + int fdout; char ** parg; const char * aclr_set; const char * aclr_color; const char * aclr_unset; - if (fprintf(stdout,"%s%s%s: %s%s%s%s:%s", + fdout = slbt_driver_fdout(dctx); + + if (slbt_dprintf( + fdout,"%s%s%s: %s%s%s%s:%s", aclr_bold,aclr_magenta, dctx->program,aclr_reset, aclr_bold,aclr_green,step,aclr_reset) < 0) @@ -44,7 +51,8 @@ static int slbt_output_exec_annotated( aclr_unset = aclr_reset; } - if (fprintf(stdout," %s%s%s%s", + if (slbt_dprintf( + fdout," %s%s%s%s", aclr_set,aclr_color, *parg, aclr_unset) < 0) @@ -52,10 +60,10 @@ static int slbt_output_exec_annotated( } - if (fputc('\n',stdout) < 0) + if (slbt_dprintf(fdout,"\n") < 0) return SLBT_SYSTEM_ERROR(dctx); - return fflush(stdout); + return 0; } static int slbt_output_exec_plain( @@ -63,21 +71,22 @@ static int slbt_output_exec_plain( const struct slbt_exec_ctx * ectx, const char * step) { + int fdout; char ** parg; - if (fprintf(stdout,"%s: %s:",dctx->program,step) < 0) + fdout = slbt_driver_fdout(dctx); + + if (slbt_dprintf(fdout,"%s: %s:",dctx->program,step) < 0) return SLBT_SYSTEM_ERROR(dctx); for (parg=ectx->argv; *parg; parg++) - if (fprintf(stdout," %s",*parg) < 0) + if (slbt_dprintf(fdout," %s",*parg) < 0) return SLBT_SYSTEM_ERROR(dctx); - if (fputc('\n',stdout) < 0) + if (slbt_dprintf(fdout,"\n") < 0) return SLBT_SYSTEM_ERROR(dctx); - return fflush(stdout) - ? SLBT_SYSTEM_ERROR(dctx) - : 0; + return 0; } int slbt_output_exec( @@ -85,13 +94,15 @@ int slbt_output_exec( const struct slbt_exec_ctx * ectx, const char * step) { + int fdout = slbt_driver_fdout(dctx); + if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER) return slbt_output_exec_plain(dctx,ectx,step); else if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_ALWAYS) return slbt_output_exec_annotated(dctx,ectx,step); - else if (isatty(STDOUT_FILENO)) + else if (isatty(fdout)) return slbt_output_exec_annotated(dctx,ectx,step); else diff --git a/src/output/slbt_output_features.c b/src/output/slbt_output_features.c index b0252fa..577ca5a 100644 --- a/src/output/slbt_output_features.c +++ b/src/output/slbt_output_features.c @@ -9,6 +9,8 @@ #include <stdbool.h> #include <slibtool/slibtool.h> +#include "slibtool_driver_impl.h" +#include "slibtool_dprintf_impl.h" #include "slibtool_errinfo_impl.h" static const char enable[] = "enable"; @@ -16,25 +18,26 @@ static const char disable[] = "disable"; int slbt_output_features(const struct slbt_driver_ctx * dctx) { + int fdout; const char * shared_option; const char * static_option; + fdout = slbt_driver_fdout(dctx); + shared_option = (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_SHARED) ? disable : enable; static_option = (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_STATIC) ? disable : enable; - if (fprintf(stdout,"host: %s\n",dctx->cctx->host.host) < 0) + if (slbt_dprintf(fdout,"host: %s\n",dctx->cctx->host.host) < 0) return SLBT_SYSTEM_ERROR(dctx); - if (fprintf(stdout,"%s shared libraries\n",shared_option) < 0) + if (slbt_dprintf(fdout,"%s shared libraries\n",shared_option) < 0) return SLBT_SYSTEM_ERROR(dctx); - if (fprintf(stdout,"%s static libraries\n",static_option) < 0) + if (slbt_dprintf(fdout,"%s static libraries\n",static_option) < 0) return SLBT_SYSTEM_ERROR(dctx); - return fflush(stdout) - ? SLBT_SYSTEM_ERROR(dctx) - : 0; + return 0; } diff --git a/src/slibtool.c b/src/slibtool.c index 6930fd6..fb7e9bb 100644 --- a/src/slibtool.c +++ b/src/slibtool.c @@ -8,5 +8,5 @@ int main(int argc, char ** argv, char ** envp) { - return slbt_main(argc,argv,envp); + return slbt_main(argc,argv,envp,0); } |