scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 33e76ce23d79e16f3e4bc0abfcb62e2e43c1845a
parent ef40427c63d70059cae3a26daef388322389ccec
Author: Quentin Rameau <quinq@fifth.space>
Date:   Sat, 18 Jun 2016 14:19:19 +0200

[cc1] fix and refactor the tool name check

Don't use argv0 which is not set before ARGBEGIN.

Diffstat:
Mcc1/main.c | 13+++++--------
1 file changed, 5 insertions(+), 8 deletions(-)

diff --git a/cc1/main.c b/cc1/main.c @@ -15,7 +15,7 @@ char *argv0; int warnings; jmp_buf recover; -static char *base, *output; +static char *name, *output; static struct items uflags; int onlycpp; @@ -31,7 +31,7 @@ clean(void) 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,17 +41,14 @@ usage(void) int main(int argc, char *argv[]) { - char *base; + char *cp; int i; atexit(clean); 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 @@ main(int argc, char *argv[]) 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)