commit 33e76ce23d79e16f3e4bc0abfcb62e2e43c1845a
Author:     Quentin Rameau <[email protected]>
AuthorDate: Sat Jun 18 14:19:19 2016 +0200
Commit:     Quentin Rameau <[email protected]>
CommitDate: Sat Jun 18 14:19:19 2016 +0200

    [cc1] fix and refactor the tool name check
    
    Don't use argv0 which is not set before ARGBEGIN.

diff --git a/cc1/main.c b/cc1/main.c
index d7fa487..50b2651 100644
--- 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)

Reply via email to