firasuke / cross / slibtool

Forked from cross/slibtool 6 months ago
Clone

a82cc2 driver, library interfaces: support alternate fd's for input/output/error/log.

Authored and Committed by midipix 6 years ago
    driver, library interfaces: support alternate fd's for input/output/error/log.
    
        
file modified
+16 -3
include/slibtool/slibtool.h CHANGED
@@ -122,6 +122,13 @@ struct slbt_source_version {
122
122
const char * commit;
123
123
};
124
124
125
+ struct slbt_fd_ctx {
126
+ int fdin;
127
+ int fdout;
128
+ int fderr;
129
+ int fdlog;
130
+ };
131
+
125
132
struct slbt_exec_ctx {
126
133
char * program;
127
134
char * compiler;
@@ -247,10 +254,15 @@ struct slbt_driver_ctx {
247
254
slbt_api const struct slbt_source_version * slbt_source_version(void);
248
255
249
256
/* driver api */
250
- slbt_api int slbt_get_driver_ctx (char ** argv, char ** envp, uint32_t flags, struct slbt_driver_ctx **);
251
- slbt_api int slbt_create_driver_ctx (const struct slbt_common_ctx *, struct slbt_driver_ctx **);
257
+ slbt_api int slbt_get_driver_ctx (char ** argv, char ** envp, uint32_t flags,
258
+ const struct slbt_fd_ctx *, struct slbt_driver_ctx **);
259
+ slbt_api int slbt_create_driver_ctx (const struct slbt_common_ctx *,
260
+ const struct slbt_fd_ctx *, struct slbt_driver_ctx **);
252
261
slbt_api void slbt_free_driver_ctx (struct slbt_driver_ctx *);
253
262
263
+ slbt_api int slbt_get_driver_fdctx (const struct slbt_driver_ctx *, struct slbt_fd_ctx *);
264
+ slbt_api int slbt_set_driver_fdctx (struct slbt_driver_ctx *, const struct slbt_fd_ctx *);
265
+
254
266
/* execution context api */
255
267
slbt_api int slbt_get_exec_ctx (const struct slbt_driver_ctx *, struct slbt_exec_ctx **);
256
268
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_
276
288
slbt_api int slbt_dump_machine (const char * compiler, char * machine, size_t bufsize);
277
289
278
290
/* utility api */
279
- slbt_api int slbt_main (int, char **, char **);
291
+ slbt_api int slbt_main (int, char **, char **,
292
+ const struct slbt_fd_ctx *);
280
293
slbt_api int slbt_output_config (const struct slbt_driver_ctx *);
281
294
slbt_api int slbt_output_features (const struct slbt_driver_ctx *);
282
295
slbt_api int slbt_output_exec (const struct slbt_driver_ctx *, const struct slbt_exec_ctx *, const char *);
file modified
+14 -11
src/driver/slbt_amain.c CHANGED
@@ -10,6 +10,7 @@
10
10
#include <errno.h>
11
11
#include <slibtool/slibtool.h>
12
12
#include "slibtool_driver_impl.h"
13
+ #include "slibtool_dprintf_impl.h"
13
14
14
15
#ifndef SLBT_DRIVER_FLAGS
15
16
#define SLBT_DRIVER_FLAGS SLBT_DRIVER_VERBOSITY_ERRORS \
@@ -32,17 +33,17 @@ static const char * const slbt_ver_plain[6] = {
32
33
"",""
33
34
};
34
35
35
- static ssize_t slbt_version(struct slbt_driver_ctx * dctx)
36
+ static ssize_t slbt_version(int fdout, struct slbt_driver_ctx * dctx)
36
37
{
37
38
const struct slbt_source_version * verinfo;
38
39
const char * const * verclr;
39
40
bool gitver;
40
41
41
42
verinfo = slbt_source_version();
42
- verclr = isatty(STDOUT_FILENO) ? slbt_ver_color : slbt_ver_plain;
43
+ verclr = isatty(fdout) ? slbt_ver_color : slbt_ver_plain;
43
44
gitver = strcmp(verinfo->commit,"unknown");
44
45
45
- return fprintf(stdout,vermsg,
46
+ return slbt_dprintf(fdout,vermsg,
46
47
verclr[0],dctx->program,verclr[1],
47
48
verclr[2],verinfo->major,verinfo->minor,
48
49
verinfo->revision,verclr[3],
@@ -82,15 +83,20 @@ static int slbt_exit(struct slbt_driver_ctx * dctx, int ret)
82
83
return ret;
83
84
}
84
85
85
- int slbt_main(int argc, char ** argv, char ** envp)
86
+ int slbt_main(int argc, char ** argv, char ** envp,
87
+ const struct slbt_fd_ctx * fdctx)
86
88
{
87
89
int ret;
90
+ int fdout;
88
91
uint64_t flags;
89
92
struct slbt_driver_ctx * dctx;
90
93
char * program;
91
94
char * dash;
92
95
char * sargv[5];
93
96
97
+ flags = SLBT_DRIVER_FLAGS;
98
+ fdout = fdctx ? fdctx->fdout : STDOUT_FILENO;
99
+
94
100
/* --version only? */
95
101
if ((argc == 2) && (!strcmp(argv[1],"--version")
96
102
|| !strcmp(argv[1],"--help-all")
@@ -102,8 +108,8 @@ int slbt_main(int argc, char ** argv, char ** envp)
102
108
sargv[3] = "<compiler>";
103
109
sargv[4] = 0;
104
110
105
- return (slbt_get_driver_ctx(sargv,envp,SLBT_DRIVER_FLAGS,&dctx))
106
- ? SLBT_ERROR : (slbt_version(dctx) < 0)
111
+ return (slbt_get_driver_ctx(sargv,envp,flags,fdctx,&dctx))
112
+ ? SLBT_ERROR : (slbt_version(fdout,dctx) < 0)
107
113
? slbt_exit(dctx,SLBT_ERROR)
108
114
: slbt_exit(dctx,SLBT_OK);
109
115
}
@@ -128,9 +134,6 @@ int slbt_main(int argc, char ** argv, char ** envp)
128
134
else if (!(strcmp(dash,"static")))
129
135
flags = SLBT_DRIVER_FLAGS | SLBT_DRIVER_DISABLE_SHARED;
130
136
131
- else
132
- flags = SLBT_DRIVER_FLAGS;
133
-
134
137
/* debug */
135
138
if (!(strcmp(program,"dlibtool")))
136
139
flags |= SLBT_DRIVER_DEBUG;
@@ -148,13 +151,13 @@ int slbt_main(int argc, char ** argv, char ** envp)
148
151
flags |= SLBT_DRIVER_LEGABITS;
149
152
150
153
/* driver context */
151
- if ((ret = slbt_get_driver_ctx(argv,envp,flags,&dctx)))
154
+ if ((ret = slbt_get_driver_ctx(argv,envp,flags,fdctx,&dctx)))
152
155
return (ret == SLBT_USAGE)
153
156
? !--argc
154
157
: SLBT_ERROR;
155
158
156
159
if (dctx->cctx->drvflags & SLBT_DRIVER_VERSION)
157
- if ((slbt_version(dctx)) < 0)
160
+ if ((slbt_version(fdout,dctx)) < 0)
158
161
return slbt_exit(dctx,SLBT_ERROR);
159
162
160
163
slbt_perform_driver_actions(dctx);
file modified
+89 -28
src/driver/slbt_driver_ctx.c CHANGED
@@ -79,7 +79,7 @@ struct slbt_driver_ctx_alloc {
79
79
uint64_t guard;
80
80
};
81
81
82
- static void slbt_output_raw_vector(char ** argv, char ** envp)
82
+ static void slbt_output_raw_vector(int fderr, char ** argv, char ** envp)
83
83
{
84
84
char ** parg;
85
85
char * dot;
@@ -88,10 +88,10 @@ static void slbt_output_raw_vector(char ** argv, char ** envp)
88
88
89
89
(void)envp;
90
90
91
- if ((fcolor = isatty(STDERR_FILENO)))
92
- fprintf(stderr,"%s%s",aclr_bold,aclr_red);
91
+ if ((fcolor = isatty(fderr)))
92
+ slbt_dprintf(fderr,"%s%s",aclr_bold,aclr_red);
93
93
94
- fprintf(stderr,"\n\n\n%s",argv[0]);
94
+ slbt_dprintf(fderr,"\n\n\n%s",argv[0]);
95
95
96
96
for (parg=&argv[1]; *parg; parg++) {
97
97
if (!fcolor)
@@ -107,10 +107,10 @@ static void slbt_output_raw_vector(char ** argv, char ** envp)
107
107
else
108
108
color = aclr_white;
109
109
110
- fprintf(stderr," %s%s",color,*parg);
110
+ slbt_dprintf(fderr," %s%s",color,*parg);
111
111
}
112
112
113
- fprintf(stderr,"%s\n\n",fcolor ? aclr_reset : "");
113
+ slbt_dprintf(fderr,"%s\n\n",fcolor ? aclr_reset : "");
114
114
}
115
115
116
116
static uint32_t slbt_argv_flags(uint32_t flags)
@@ -130,6 +130,7 @@ static uint32_t slbt_argv_flags(uint32_t flags)
130
130
}
131
131
132
132
static int slbt_driver_usage(
133
+ int fdout,
133
134
const char * program,
134
135
const char * arg,
135
136
const struct argv_option ** optv,
@@ -141,7 +142,7 @@ static int slbt_driver_usage(
141
142
"Usage: %s [options] <file>...\n" "Options:\n",
142
143
program);
143
144
144
- argv_usage(STDOUT_FILENO,header,optv,arg);
145
+ argv_usage(fdout,header,optv,arg);
145
146
argv_free(meta);
146
147
147
148
return SLBT_USAGE;
@@ -149,6 +150,7 @@ static int slbt_driver_usage(
149
150
150
151
static struct slbt_driver_ctx_impl * slbt_driver_ctx_alloc(
151
152
struct argv_meta * meta,
153
+ const struct slbt_fd_ctx * fdctx,
152
154
const struct slbt_common_ctx * cctx)
153
155
{
154
156
struct slbt_driver_ctx_alloc * ictx;
@@ -160,8 +162,8 @@ static struct slbt_driver_ctx_impl * slbt_driver_ctx_alloc(
160
162
if (!(ictx = calloc(1,size)))
161
163
return 0;
162
164
163
- if (cctx)
164
- memcpy(&ictx->ctx.cctx,cctx,sizeof(*cctx));
165
+ memcpy(&ictx->ctx.fdctx,fdctx,sizeof(*fdctx));
166
+ memcpy(&ictx->ctx.cctx,cctx,sizeof(*cctx));
165
167
166
168
elements = sizeof(ictx->ctx.erribuf) / sizeof(*ictx->ctx.erribuf);
167
169
@@ -182,7 +184,8 @@ static int slbt_get_driver_ctx_fail(struct argv_meta * meta)
182
184
static int slbt_split_argv(
183
185
char ** argv,
184
186
uint32_t flags,
185
- struct slbt_split_vector * sargv)
187
+ struct slbt_split_vector * sargv,
188
+ int fderr)
186
189
{
187
190
int i;
188
191
int argc;
@@ -209,7 +212,9 @@ static int slbt_split_argv(
209
212
argv_optv_init(slbt_default_options,optv);
210
213
211
214
if (!argv[1] && (flags & SLBT_DRIVER_VERBOSITY_USAGE))
212
- return slbt_driver_usage(program,0,optv,0);
215
+ return slbt_driver_usage(
216
+ fderr,program,
217
+ 0,optv,0);
213
218
214
219
/* initial argv scan: ... --mode=xxx ... <compiler> ... */
215
220
argv_scan(argv,optv,&ctx,0);
@@ -220,7 +225,7 @@ static int slbt_split_argv(
220
225
argv_get(
221
226
argv,optv,
222
227
slbt_argv_flags(flags),
223
- STDERR_FILENO);
228
+ fderr);
224
229
return -1;
225
230
}
226
231
@@ -229,10 +234,10 @@ static int slbt_split_argv(
229
234
compiler = argv[ctx.unitidx];
230
235
argv[ctx.unitidx] = 0;
231
236
232
- meta = argv_get(argv,optv,ARGV_VERBOSITY_NONE,STDERR_FILENO);
237
+ meta = argv_get(argv,optv,ARGV_VERBOSITY_NONE,fderr);
233
238
argv[ctx.unitidx] = compiler;
234
239
} else {
235
- meta = argv_get(argv,optv,ARGV_VERBOSITY_NONE,STDERR_FILENO);
240
+ meta = argv_get(argv,optv,ARGV_VERBOSITY_NONE,fderr);
236
241
}
237
242
238
243
/* missing all of --mode, --config, --features, and --finish? */
@@ -251,7 +256,7 @@ static int slbt_split_argv(
251
256
argv_free(meta);
252
257
253
258
if (!mode && !config && !finish && !features) {
254
- fprintf(stderr,
259
+ slbt_dprintf(fderr,
255
260
"%s: error: --mode must be specified.\n",
256
261
program);
257
262
return -1;
@@ -260,7 +265,7 @@ static int slbt_split_argv(
260
265
/* missing compiler? */
261
266
if (!ctx.unitidx && !finish && !features) {
262
267
if (flags & SLBT_DRIVER_VERBOSITY_ERRORS)
263
- fprintf(stderr,
268
+ slbt_dprintf(fderr,
264
269
"%s: error: <compiler> is missing.\n",
265
270
program);
266
271
return -1;
@@ -773,7 +778,7 @@ static int slbt_init_version_info(
773
778
774
779
if (current < age) {
775
780
if (ictx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS)
776
- fprintf(stderr,
781
+ slbt_dprintf(ictx->fdctx.fderr,
777
782
"%s: error: invalid version info: "
778
783
"<current> may not be smaller than <age>.\n",
779
784
argv_program_name(ictx->cctx.targv[0]));
@@ -795,7 +800,9 @@ static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx)
795
800
const char * base;
796
801
char * dot;
797
802
bool fmodule;
803
+ int fderr;
798
804
805
+ fderr = ctx->fdctx.fderr;
799
806
program = argv_program_name(ctx->cctx.targv[0]);
800
807
libname = 0;
801
808
prefix = 0;
@@ -804,7 +811,7 @@ static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx)
804
811
/* output */
805
812
if (!(ctx->cctx.output)) {
806
813
if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS)
807
- fprintf(stderr,
814
+ slbt_dprintf(fderr,
808
815
"%s: error: output file must be "
809
816
"specified in link mode.\n",
810
817
program);
@@ -829,7 +836,7 @@ static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx)
829
836
libname = base;
830
837
else {
831
838
if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS)
832
- fprintf(stderr,
839
+ slbt_dprintf(fderr,
833
840
"%s: error: output file prefix does "
834
841
"not match its (archive) suffix; "
835
842
"the expected prefix was '%s'\n",
@@ -846,7 +853,7 @@ static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx)
846
853
libname = base;
847
854
else {
848
855
if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS)
849
- fprintf(stderr,
856
+ slbt_dprintf(fderr,
850
857
"%s: error: output file prefix does "
851
858
"not match its (shared library) suffix; "
852
859
"the expected prefix was '%s'\n",
@@ -867,7 +874,7 @@ static int slbt_init_link_params(struct slbt_driver_ctx_impl * ctx)
867
874
fmodule = true;
868
875
} else {
869
876
if (ctx->cctx.drvflags & SLBT_DRIVER_VERBOSITY_ERRORS)
870
- fprintf(stderr,
877
+ slbt_dprintf(fderr,
871
878
"%s: error: output file prefix does "
872
879
"not match its (libtool wrapper) suffix; "
873
880
"the expected prefix was '%s'\n",
@@ -896,6 +903,7 @@ int slbt_get_driver_ctx(
896
903
char ** argv,
897
904
char ** envp,
898
905
uint32_t flags,
906
+ const struct slbt_fd_ctx * fdctx,
899
907
struct slbt_driver_ctx ** pctx)
900
908
{
901
909
struct slbt_split_vector sargv;
@@ -908,13 +916,22 @@ int slbt_get_driver_ctx(
908
916
909
917
argv_optv_init(slbt_default_options,optv);
910
918
911
- if (slbt_split_argv(argv,flags,&sargv))
919
+ if (!fdctx) {
920
+ fdctx = &(const struct slbt_fd_ctx) {
921
+ .fdin = STDIN_FILENO,
922
+ .fdout = STDOUT_FILENO,
923
+ .fderr = STDERR_FILENO,
924
+ .fdlog = (-1)
925
+ };
926
+ }
927
+
928
+ if (slbt_split_argv(argv,flags,&sargv,fdctx->fderr))
912
929
return -1;
913
930
914
931
if (!(meta = argv_get(
915
932
sargv.targv,optv,
916
933
slbt_argv_flags(flags),
917
- STDERR_FILENO)))
934
+ fdctx->fderr)))
918
935
return -1;
919
936
920
937
program = argv_program_name(argv[0]);
@@ -933,7 +950,9 @@ int slbt_get_driver_ctx(
933
950
case TAG_HELP:
934
951
case TAG_HELP_ALL:
935
952
if (flags & SLBT_DRIVER_VERBOSITY_USAGE)
936
- return slbt_driver_usage(program,entry->arg,optv,meta);
953
+ return slbt_driver_usage(
954
+ fdctx->fdout,program,
955
+ entry->arg,optv,meta);
937
956
938
957
case TAG_VERSION:
939
958
cctx.drvflags |= SLBT_DRIVER_VERSION;
@@ -1184,7 +1203,7 @@ int slbt_get_driver_ctx(
1184
1203
1185
1204
/* debug: raw argument vector */
1186
1205
if (cctx.drvflags & SLBT_DRIVER_DEBUG)
1187
- slbt_output_raw_vector(argv,envp);
1206
+ slbt_output_raw_vector(fdctx->fderr,argv,envp);
1188
1207
1189
1208
/* -o in install mode means USER */
1190
1209
if ((cctx.mode == SLBT_MODE_INSTALL) && cctx.output) {
@@ -1197,7 +1216,7 @@ int slbt_get_driver_ctx(
1197
1216
cctx.mode = SLBT_MODE_INFO;
1198
1217
1199
1218
/* driver context */
1200
- if (!(ctx = slbt_driver_ctx_alloc(meta,&cctx)))
1219
+ if (!(ctx = slbt_driver_ctx_alloc(meta,fdctx,&cctx)))
1201
1220
return slbt_get_driver_ctx_fail(meta);
1202
1221
1203
1222
ctx->ctx.program = program;
@@ -1252,6 +1271,7 @@ int slbt_get_driver_ctx(
1252
1271
1253
1272
int slbt_create_driver_ctx(
1254
1273
const struct slbt_common_ctx * cctx,
1274
+ const struct slbt_fd_ctx * fdctx,
1255
1275
struct slbt_driver_ctx ** pctx)
1256
1276
{
1257
1277
const struct argv_option * optv[SLBT_OPTV_ELEMENTS];
@@ -1261,10 +1281,19 @@ int slbt_create_driver_ctx(
1261
1281
1262
1282
argv_optv_init(slbt_default_options,optv);
1263
1283
1264
- if (!(meta = argv_get(argv,optv,0,STDERR_FILENO)))
1284
+ if (!fdctx) {
1285
+ fdctx = &(const struct slbt_fd_ctx) {
1286
+ .fdin = STDIN_FILENO,
1287
+ .fdout = STDOUT_FILENO,
1288
+ .fderr = STDERR_FILENO,
1289
+ .fdlog = (-1)
1290
+ };
1291
+ }
1292
+
1293
+ if (!(meta = argv_get(argv,optv,0,fdctx->fderr)))
1265
1294
return -1;
1266
1295
1267
- if (!(ctx = slbt_driver_ctx_alloc(meta,cctx)))
1296
+ if (!(ctx = slbt_driver_ctx_alloc(meta,fdctx,cctx)))
1268
1297
return slbt_get_driver_ctx_fail(0);
1269
1298
1270
1299
ctx->ctx.cctx = &ctx->cctx;
@@ -1364,3 +1393,35 @@ const struct slbt_source_version * slbt_source_version(void)
1364
1393
{
1365
1394
return &slbt_src_version;
1366
1395
}
1396
+
1397
+ int slbt_get_driver_fdctx(
1398
+ const struct slbt_driver_ctx * dctx,
1399
+ struct slbt_fd_ctx * fdctx)
1400
+ {
1401
+ struct slbt_driver_ctx_impl * ictx;
1402
+
1403
+ ictx = slbt_get_driver_ictx(dctx);
1404
+
1405
+ fdctx->fdin = ictx->fdctx.fdin;
1406
+ fdctx->fdout = ictx->fdctx.fdout;
1407
+ fdctx->fderr = ictx->fdctx.fderr;
1408
+ fdctx->fdlog = ictx->fdctx.fdlog;
1409
+
1410
+ return 0;
1411
+ }
1412
+
1413
+ int slbt_set_driver_fdctx(
1414
+ struct slbt_driver_ctx * dctx,
1415
+ const struct slbt_fd_ctx * fdctx)
1416
+ {
1417
+ struct slbt_driver_ctx_impl * ictx;
1418
+
1419
+ ictx = slbt_get_driver_ictx(dctx);
1420
+
1421
+ ictx->fdctx.fdin = fdctx->fdin;
1422
+ ictx->fdctx.fdout = fdctx->fdout;
1423
+ ictx->fdctx.fderr = fdctx->fderr;
1424
+ ictx->fdctx.fdlog = fdctx->fdlog;
1425
+
1426
+ return 0;
1427
+ }
src/internal/slibtool_driver_impl.h CHANGED
@@ -83,6 +83,7 @@ struct slbt_driver_ctx_impl {
83
83
struct slbt_driver_ctx ctx;
84
84
struct slbt_host_strs host;
85
85
struct slbt_host_strs ahost;
86
+ struct slbt_fd_ctx fdctx;
86
87
char * libname;
87
88
char ** targv;
88
89
char ** cargv;
@@ -104,4 +105,32 @@ static inline struct slbt_driver_ctx_impl * slbt_get_driver_ictx(const struct sl
104
105
return 0;
105
106
}
106
107
108
+ static inline int slbt_driver_fdin(const struct slbt_driver_ctx * dctx)
109
+ {
110
+ struct slbt_fd_ctx fdctx;
111
+ slbt_get_driver_fdctx(dctx,&fdctx);
112
+ return fdctx.fdin;
113
+ }
114
+
115
+ static inline int slbt_driver_fdout(const struct slbt_driver_ctx * dctx)
116
+ {
117
+ struct slbt_fd_ctx fdctx;
118
+ slbt_get_driver_fdctx(dctx,&fdctx);
119
+ return fdctx.fdout;
120
+ }
121
+
122
+ static inline int slbt_driver_fderr(const struct slbt_driver_ctx * dctx)
123
+ {
124
+ struct slbt_fd_ctx fdctx;
125
+ slbt_get_driver_fdctx(dctx,&fdctx);
126
+ return fdctx.fderr;
127
+ }
128
+
129
+ static inline int slbt_driver_fdlog(const struct slbt_driver_ctx * dctx)
130
+ {
131
+ struct slbt_fd_ctx fdctx;
132
+ slbt_get_driver_fdctx(dctx,&fdctx);
133
+ return fdctx.fdlog;
134
+ }
135
+
107
136
#endif
file modified
+10 -5
src/logic/slbt_exec_install.c CHANGED
@@ -23,6 +23,7 @@
23
23
#include "argv/argv.h"
24
24
25
25
static int slbt_install_usage(
26
+ int fdout,
26
27
const char * program,
27
28
const char * arg,
28
29
const struct argv_option ** optv,
@@ -35,7 +36,7 @@ static int slbt_install_usage(
35
36
"Options:\n",
36
37
program);
37
38
38
- argv_usage(STDOUT_FILENO,header,optv,arg);
39
+ argv_usage(fdout,header,optv,arg);
39
40
argv_free(meta);
40
41
41
42
return SLBT_USAGE;
@@ -536,6 +537,7 @@ int slbt_exec_install(
536
537
struct slbt_exec_ctx * ectx)
537
538
{
538
539
int ret;
540
+ int fdout;
539
541
char ** argv;
540
542
char ** iargv;
541
543
char ** src;
@@ -565,6 +567,7 @@ int slbt_exec_install(
565
567
slbt_reset_arguments(ectx);
566
568
slbt_disable_placeholders(ectx);
567
569
iargv = ectx->cargv;
570
+ fdout = slbt_driver_fdout(dctx);
568
571
569
572
/* work around non-conforming uses of --mode=install */
570
573
if (!(strcmp(iargv[0],"/bin/sh")) || !strcmp(iargv[0],"/bin/bash"))
@@ -574,16 +577,18 @@ int slbt_exec_install(
574
577
argv_optv_init(slbt_install_options,optv);
575
578
576
579
if (!iargv[1] && (dctx->cctx->drvflags & SLBT_DRIVER_VERBOSITY_USAGE))
577
- return slbt_install_usage(dctx->program,0,optv,0);
580
+ return slbt_install_usage(
581
+ fdout,
582
+ dctx->program,
583
+ 0,optv,0);
578
584
579
585
/* <install> argv meta */
580
586
if (!(meta = argv_get(
581
- iargv,
587
+ iargv,optv,
582
- optv,
583
588
dctx->cctx->drvflags & SLBT_DRIVER_VERBOSITY_ERRORS
584
589
? ARGV_VERBOSITY_ERRORS
585
590
: ARGV_VERBOSITY_NONE,
586
- STDERR_FILENO)))
591
+ fdout)))
587
592
return slbt_exec_install_fail(
588
593
actx,meta,
589
594
SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_INSTALL_FAIL));
src/logic/slbt_exec_uninstall.c CHANGED
@@ -21,6 +21,7 @@
21
21
#include "argv/argv.h"
22
22
23
23
static int slbt_uninstall_usage(
24
+ int fdout,
24
25
const char * program,
25
26
const char * arg,
26
27
const struct argv_option ** optv,
@@ -33,7 +34,7 @@ static int slbt_uninstall_usage(
33
34
"Options:\n",
34
35
program);
35
36
36
- argv_usage(STDOUT_FILENO,header,optv,arg);
37
+ argv_usage(fdout,header,optv,arg);
37
38
argv_free(meta);
38
39
39
40
return SLBT_USAGE;
@@ -245,6 +246,7 @@ int slbt_exec_uninstall(
245
246
struct slbt_exec_ctx * ectx)
246
247
{
247
248
int ret;
249
+ int fdout;
248
250
char ** argv;
249
251
char ** iargv;
250
252
uint32_t flags;
@@ -269,6 +271,7 @@ int slbt_exec_uninstall(
269
271
slbt_reset_arguments(ectx);
270
272
slbt_disable_placeholders(ectx);
271
273
iargv = ectx->cargv;
274
+ fdout = slbt_driver_fdout(dctx);
272
275
273
276
/* work around non-conforming uses of --mode=uninstall */
274
277
if (!(strcmp(iargv[0],"/bin/sh")) || !strcmp(iargv[0],"/bin/bash"))
@@ -278,16 +281,18 @@ int slbt_exec_uninstall(
278
281
argv_optv_init(slbt_uninstall_options,optv);
279
282
280
283
if (!iargv[1] && (dctx->cctx->drvflags & SLBT_DRIVER_VERBOSITY_USAGE))
281
- return slbt_uninstall_usage(dctx->program,0,optv,0);
284
+ return slbt_uninstall_usage(
285
+ fdout,
286
+ dctx->program,
287
+ 0,optv,0);
282
288
283
289
/* <uninstall> argv meta */
284
290
if (!(meta = argv_get(
285
- iargv,
291
+ iargv,optv,
286
- optv,
287
292
dctx->cctx->drvflags & SLBT_DRIVER_VERBOSITY_ERRORS
288
293
? ARGV_VERBOSITY_ERRORS
289
294
: ARGV_VERBOSITY_NONE,
290
- STDERR_FILENO)))
295
+ fdout)))
291
296
return slbt_exec_uninstall_fail(
292
297
actx,meta,
293
298
SLBT_CUSTOM_ERROR(dctx,SLBT_ERR_UNINSTALL_FAIL));
@@ -329,7 +334,10 @@ int slbt_exec_uninstall(
329
334
330
335
/* --help */
331
336
if (flags & SLBT_UNINSTALL_HELP) {
332
- slbt_uninstall_usage(dctx->program,0,optv,meta);
337
+ slbt_uninstall_usage(
338
+ fdout,
339
+ dctx->program,
340
+ 0,optv,meta);
333
341
return 0;
334
342
}
335
343
file modified
+17 -14
src/output/slbt_output_config.c CHANGED
@@ -9,6 +9,8 @@
9
9
#include <stdbool.h>
10
10
11
11
#include <slibtool/slibtool.h>
12
+ #include "slibtool_driver_impl.h"
13
+ #include "slibtool_dprintf_impl.h"
12
14
#include "slibtool_errinfo_impl.h"
13
15
14
16
#ifndef SLBT_TAB_WIDTH
@@ -20,12 +22,13 @@
20
22
#endif
21
23
22
24
static bool slbt_output_config_line(
25
+ int fd,
23
26
const char * key,
24
27
const char * value,
25
28
const char * annotation,
26
29
int midwidth)
27
30
{
28
- return (fprintf(stdout,"%-*s%-*s%s\n",
31
+ return (slbt_dprintf(fd,"%-*s%-*s%s\n",
29
32
SLBT_KEY_WIDTH, key,
30
33
midwidth, value ? value : "",
31
34
annotation ? annotation : "") < 0)
@@ -39,11 +42,13 @@ int slbt_output_config(const struct slbt_driver_ctx * dctx)
39
42
const char * target;
40
43
int len;
41
44
int midwidth;
45
+ int fdout;
42
46
43
47
cctx = dctx->cctx;
44
48
compiler = cctx->cargv[0] ? cctx->cargv[0] : "";
45
49
target = cctx->target ? cctx->target : "";
46
50
midwidth = strlen(compiler);
51
+ fdout = slbt_driver_fdout(dctx);
47
52
48
53
if ((len = strlen(target)) > midwidth)
49
54
midwidth = len;
@@ -69,37 +74,35 @@ int slbt_output_config(const struct slbt_driver_ctx * dctx)
69
74
midwidth += SLBT_TAB_WIDTH;
70
75
midwidth &= (~(SLBT_TAB_WIDTH-1));
71
76
72
- if (slbt_output_config_line("key","value","annotation",midwidth))
77
+ if (slbt_output_config_line(fdout,"key","value","annotation",midwidth))
73
78
return SLBT_SYSTEM_ERROR(dctx);
74
79
75
- if (slbt_output_config_line("---","-----","----------",midwidth))
80
+ if (slbt_output_config_line(fdout,"---","-----","----------",midwidth))
76
81
return SLBT_SYSTEM_ERROR(dctx);
77
82
78
- if (slbt_output_config_line("compiler",cctx->cargv[0],"",midwidth))
83
+ if (slbt_output_config_line(fdout,"compiler",cctx->cargv[0],"",midwidth))
79
84
return SLBT_SYSTEM_ERROR(dctx);
80
85
81
- if (slbt_output_config_line("target",cctx->target,"",midwidth))
86
+ if (slbt_output_config_line(fdout,"target",cctx->target,"",midwidth))
82
87
return SLBT_SYSTEM_ERROR(dctx);
83
88
84
- if (slbt_output_config_line("host",cctx->host.host,cctx->cfgmeta.host,midwidth))
89
+ if (slbt_output_config_line(fdout,"host",cctx->host.host,cctx->cfgmeta.host,midwidth))
85
90
return SLBT_SYSTEM_ERROR(dctx);
86
91
87
- if (slbt_output_config_line("flavor",cctx->host.flavor,cctx->cfgmeta.flavor,midwidth))
92
+ if (slbt_output_config_line(fdout,"flavor",cctx->host.flavor,cctx->cfgmeta.flavor,midwidth))
88
93
return SLBT_SYSTEM_ERROR(dctx);
89
94
90
- if (slbt_output_config_line("ar",cctx->host.ar,cctx->cfgmeta.ar,midwidth))
95
+ if (slbt_output_config_line(fdout,"ar",cctx->host.ar,cctx->cfgmeta.ar,midwidth))
91
96
return SLBT_SYSTEM_ERROR(dctx);
92
97
93
- if (slbt_output_config_line("ranlib",cctx->host.ranlib,cctx->cfgmeta.ranlib,midwidth))
98
+ if (slbt_output_config_line(fdout,"ranlib",cctx->host.ranlib,cctx->cfgmeta.ranlib,midwidth))
94
99
return SLBT_SYSTEM_ERROR(dctx);
95
100
96
- if (slbt_output_config_line("dlltool",cctx->host.dlltool,cctx->cfgmeta.dlltool,midwidth))
101
+ if (slbt_output_config_line(fdout,"dlltool",cctx->host.dlltool,cctx->cfgmeta.dlltool,midwidth))
97
102
return SLBT_SYSTEM_ERROR(dctx);
98
103
99
- if (slbt_output_config_line("mdso",cctx->host.mdso,cctx->cfgmeta.mdso,midwidth))
104
+ if (slbt_output_config_line(fdout,"mdso",cctx->host.mdso,cctx->cfgmeta.mdso,midwidth))
100
105
return SLBT_SYSTEM_ERROR(dctx);
101
106
102
- return fflush(stdout)
107
+ return 0;
103
- ? SLBT_SYSTEM_ERROR(dctx)
104
- : 0;
105
108
}
src/output/slbt_output_error.c CHANGED
@@ -10,6 +10,9 @@
10
10
#include <unistd.h>
11
11
#include <slibtool/slibtool.h>
12
12
13
+ #include "slibtool_driver_impl.h"
14
+ #include "slibtool_dprintf_impl.h"
15
+
13
16
static const char aclr_reset[] = "\x1b[0m";
14
17
static const char aclr_bold[] = "\x1b[1m";
15
18
@@ -56,7 +59,8 @@ static int slbt_output_error_record_plain(
56
59
{
57
60
const char * errdesc = slbt_output_strerror(erri);
58
61
59
- if (fprintf(stderr,"%s: %s %s(), line %d%s%s.\n",
62
+ if (slbt_dprintf(slbt_driver_fderr(dctx),
63
+ "%s: %s %s(), line %d%s%s.\n",
60
64
dctx->program,
61
65
slbt_output_error_header(erri),
62
66
erri->efunction,
@@ -65,7 +69,7 @@ static int slbt_output_error_record_plain(
65
69
errdesc) < 0)
66
70
return -1;
67
71
68
- return fflush(stderr);
72
+ return 0;
69
73
}
70
74
71
75
static int slbt_output_error_record_annotated(
@@ -74,8 +78,8 @@ static int slbt_output_error_record_annotated(
74
78
{
75
79
const char * errdesc = slbt_output_strerror(erri);
76
80
77
- if (fprintf(
78
- stderr,
81
+ if (slbt_dprintf(
82
+ slbt_driver_fderr(dctx),
79
83
"%s%s%s:%s %s%s%s %s%s%s()%s, %s%sline %d%s%s%s%s%s.\n",
80
84
81
85
aclr_bold,aclr_magenta,
@@ -100,20 +104,22 @@ static int slbt_output_error_record_annotated(
100
104
aclr_reset) < 0)
101
105
return -1;
102
106
103
- return fflush(stderr);
107
+ return 0;
104
108
}
105
109
106
110
int slbt_output_error_record(
107
111
const struct slbt_driver_ctx * dctx,
108
112
const struct slbt_error_info * erri)
109
113
{
114
+ int fderr = slbt_driver_fderr(dctx);
115
+
110
116
if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER)
111
117
return slbt_output_error_record_plain(dctx,erri);
112
118
113
119
else if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_ALWAYS)
114
120
return slbt_output_error_record_annotated(dctx,erri);
115
121
116
- else if (isatty(STDERR_FILENO))
122
+ else if (isatty(fderr))
117
123
return slbt_output_error_record_annotated(dctx,erri);
118
124
119
125
else
@@ -144,13 +150,15 @@ static int slbt_output_error_vector_annotated(const struct slbt_driver_ctx * dct
144
150
145
151
int slbt_output_error_vector(const struct slbt_driver_ctx * dctx)
146
152
{
153
+ int fderr = slbt_driver_fderr(dctx);
154
+
147
155
if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER)
148
156
return slbt_output_error_vector_plain(dctx);
149
157
150
158
else if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_ALWAYS)
151
159
return slbt_output_error_vector_annotated(dctx);
152
160
153
- else if (isatty(STDERR_FILENO))
161
+ else if (isatty(fderr))
154
162
return slbt_output_error_vector_annotated(dctx);
155
163
156
164
else
file modified
+22 -11
src/output/slbt_output_exec.c CHANGED
@@ -7,6 +7,9 @@
7
7
#include <unistd.h>
8
8
#include <stdio.h>
9
9
#include <slibtool/slibtool.h>
10
+
11
+ #include "slibtool_driver_impl.h"
12
+ #include "slibtool_dprintf_impl.h"
10
13
#include "slibtool_errinfo_impl.h"
11
14
12
15
static const char aclr_null[] = "";
@@ -22,12 +25,16 @@ static int slbt_output_exec_annotated(
22
25
const struct slbt_exec_ctx * ectx,
23
26
const char * step)
24
27
{
28
+ int fdout;
25
29
char ** parg;
26
30
const char * aclr_set;
27
31
const char * aclr_color;
28
32
const char * aclr_unset;
29
33
30
- if (fprintf(stdout,"%s%s%s: %s%s%s%s:%s",
34
+ fdout = slbt_driver_fdout(dctx);
35
+
36
+ if (slbt_dprintf(
37
+ fdout,"%s%s%s: %s%s%s%s:%s",
31
38
aclr_bold,aclr_magenta,
32
39
dctx->program,aclr_reset,
33
40
aclr_bold,aclr_green,step,aclr_reset) < 0)
@@ -44,7 +51,8 @@ static int slbt_output_exec_annotated(
44
51
aclr_unset = aclr_reset;
45
52
}
46
53
47
- if (fprintf(stdout," %s%s%s%s",
54
+ if (slbt_dprintf(
55
+ fdout," %s%s%s%s",
48
56
aclr_set,aclr_color,
49
57
*parg,
50
58
aclr_unset) < 0)
@@ -52,10 +60,10 @@ static int slbt_output_exec_annotated(
52
60
53
61
}
54
62
55
- if (fputc('\n',stdout) < 0)
63
+ if (slbt_dprintf(fdout,"\n") < 0)
56
64
return SLBT_SYSTEM_ERROR(dctx);
57
65
58
- return fflush(stdout);
66
+ return 0;
59
67
}
60
68
61
69
static int slbt_output_exec_plain(
@@ -63,21 +71,22 @@ static int slbt_output_exec_plain(
63
71
const struct slbt_exec_ctx * ectx,
64
72
const char * step)
65
73
{
74
+ int fdout;
66
75
char ** parg;
67
76
68
- if (fprintf(stdout,"%s: %s:",dctx->program,step) < 0)
77
+ fdout = slbt_driver_fdout(dctx);
78
+
79
+ if (slbt_dprintf(fdout,"%s: %s:",dctx->program,step) < 0)
69
80
return SLBT_SYSTEM_ERROR(dctx);
70
81
71
82
for (parg=ectx->argv; *parg; parg++)
72
- if (fprintf(stdout," %s",*parg) < 0)
83
+ if (slbt_dprintf(fdout," %s",*parg) < 0)
73
84
return SLBT_SYSTEM_ERROR(dctx);
74
85
75
- if (fputc('\n',stdout) < 0)
86
+ if (slbt_dprintf(fdout,"\n") < 0)
76
87
return SLBT_SYSTEM_ERROR(dctx);
77
88
78
- return fflush(stdout)
89
+ return 0;
79
- ? SLBT_SYSTEM_ERROR(dctx)
80
- : 0;
81
90
}
82
91
83
92
int slbt_output_exec(
@@ -85,13 +94,15 @@ int slbt_output_exec(
85
94
const struct slbt_exec_ctx * ectx,
86
95
const char * step)
87
96
{
97
+ int fdout = slbt_driver_fdout(dctx);
98
+
88
99
if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_NEVER)
89
100
return slbt_output_exec_plain(dctx,ectx,step);
90
101
91
102
else if (dctx->cctx->drvflags & SLBT_DRIVER_ANNOTATE_ALWAYS)
92
103
return slbt_output_exec_annotated(dctx,ectx,step);
93
104
94
- else if (isatty(STDOUT_FILENO))
105
+ else if (isatty(fdout))
95
106
return slbt_output_exec_annotated(dctx,ectx,step);
96
107
97
108
else
src/output/slbt_output_features.c CHANGED
@@ -9,6 +9,8 @@
9
9
#include <stdbool.h>
10
10
11
11
#include <slibtool/slibtool.h>
12
+ #include "slibtool_driver_impl.h"
13
+ #include "slibtool_dprintf_impl.h"
12
14
#include "slibtool_errinfo_impl.h"
13
15
14
16
static const char enable[] = "enable";
@@ -16,25 +18,26 @@ static const char disable[] = "disable";
16
18
17
19
int slbt_output_features(const struct slbt_driver_ctx * dctx)
18
20
{
21
+ int fdout;
19
22
const char * shared_option;
20
23
const char * static_option;
21
24
25
+ fdout = slbt_driver_fdout(dctx);
26
+
22
27
shared_option = (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_SHARED)
23
28
? disable : enable;
24
29
25
30
static_option = (dctx->cctx->drvflags & SLBT_DRIVER_DISABLE_STATIC)
26
31
? disable : enable;
27
32
28
- if (fprintf(stdout,"host: %s\n",dctx->cctx->host.host) < 0)
33
+ if (slbt_dprintf(fdout,"host: %s\n",dctx->cctx->host.host) < 0)
29
34
return SLBT_SYSTEM_ERROR(dctx);
30
35
31
- if (fprintf(stdout,"%s shared libraries\n",shared_option) < 0)
36
+ if (slbt_dprintf(fdout,"%s shared libraries\n",shared_option) < 0)
32
37
return SLBT_SYSTEM_ERROR(dctx);
33
38
34
- if (fprintf(stdout,"%s static libraries\n",static_option) < 0)
39
+ if (slbt_dprintf(fdout,"%s static libraries\n",static_option) < 0)
35
40
return SLBT_SYSTEM_ERROR(dctx);
36
41
37
- return fflush(stdout)
42
+ return 0;
38
- ? SLBT_SYSTEM_ERROR(dctx)
39
- : 0;
40
43
}
file modified
+1 -1
src/slibtool.c CHANGED
@@ -8,5 +8,5 @@
8
8
9
9
int main(int argc, char ** argv, char ** envp)
10
10
{
11
- return slbt_main(argc,argv,envp);
11
+ return slbt_main(argc,argv,envp,0);
12
12
}