ref: 27ee78d5d5dc05661a28937a6c7096aa8ae64d35
parent: f5b786d721fb88f375f21b40678c046d3732e8ca
author: Quentin Rameau <quinq@fifth.space>
date: Sat Jun 18 10:19:19 EDT 2016
[cc1] fix and refactor the tool name check Don't use argv0 which is not set before ARGBEGIN.
--- a/cc1/main.c
+++ b/cc1/main.c
@@ -15,7 +15,7 @@
int warnings;
jmp_buf recover;
-static char *base, *output;
+static char *name, *output;
static struct items uflags;
int onlycpp;
@@ -31,7 +31,7 @@
static void
usage(void)
{
- die(!strcmp(base, "cpp") ?
+ die(!strcmp(name, "cpp") ?
"usage: cpp [-wd] [-D def[=val]]... [-U def]... [-I dir]... "
"[input]" :
"usage: cc1 [-Ewd] [-D def[=val]]... [-U def]... [-I dir]... "
@@ -41,7 +41,7 @@
int
main(int argc, char *argv[])
{
- char *base;
+ char *cp;
int i;
atexit(clean);
@@ -48,10 +48,7 @@
icpp();
/* if run as cpp, only run the preprocessor */
- if ((base = strrchr(argv0, '/')))
- ++base;
- else
- base = argv0;
+ name = (cp = strrchr(*argv, '/')) ? cp + 1 : *argv;
ARGBEGIN {
case 'D':
@@ -85,7 +82,7 @@
if (output && !freopen(output, "w", stdout))
die("error opening output: %s", strerror(errno));
- if (!strcmp(base, "cpp"))
+ if (!strcmp(name, "cpp"))
onlycpp = 1;
for (i = 0; i < uflags.n; ++i)