ref: 726f4aa85ece511878dfe1cb2132c34d882e5621
parent: 27ee78d5d5dc05661a28937a6c7096aa8ae64d35
author: Quentin Rameau <quinq@fifth.space>
date: Sat Jun 18 11:03:30 EDT 2016
[driver] use struct items int tool Replace args and nargs with our defined struct items.
--- a/driver/posix/scc.c
+++ b/driver/posix/scc.c
@@ -29,10 +29,10 @@
static struct tool {
char cmd[PATH_MAX];
- char **args;
char bin[16];
char *outfile;
- int nparams, nargs, in, out, init;
+ struct items args;
+ int nparams, in, out, init;
pid_t pid;
} tools[] = {
[CC1] = { .bin = "cc1", .cmd = PREFIX "/libexec/scc/", },
@@ -69,10 +69,10 @@
{
struct tool *t = &tools[tool];
- if (t->nargs < 1)
- t->nargs = 1;
+ if (t->args.n < 1)
+ t->args.n = 1;
- t->args = newitem(t->args, t->nargs++, arg);
+ t->args.s = newitem(t->args.s, t->args.n++, arg);
}
static void
@@ -80,10 +80,10 @@
{
struct tool *t = &tools[tool];
- if (t->nargs > 0)
- t->args[0] = arg;
+ if (t->args.n > 0)
+ t->args.s[0] = arg;
else
- t->args = newitem(t->args, t->nargs++, arg);
+ t->args.s = newitem(t->args.s, t->args.n++, arg);
}
static int
@@ -126,7 +126,7 @@
}
setargv0(tool, t->bin);
- t->nparams = t->nargs;
+ t->nparams = t->args.n;
t->init = 1;
return tool;
@@ -239,7 +239,7 @@
dup2(t->out, 1);
if (t->in > -1)
dup2(t->in, 0);
- execvp(t->cmd, t->args);
+ execvp(t->cmd, t->args.s);
fprintf(stderr, "scc: execvp %s: %s\n",
t->cmd, strerror(errno));
_exit(1);
@@ -289,9 +289,9 @@
}
if (tool >= failed && t->outfile)
unlink(t->outfile);
- for (i = t->nparams; i < t->nargs; ++i)
- free(t->args[i]);
- t->nargs = t->nparams;
+ for (i = t->nparams; i < t->args.n; ++i)
+ free(t->args.s[i]);
+ t->args.n = t->nparams;
t->pid = 0;
}
}