Quick Search:

Mode

Context

Displaying 3 lines of context. None | Less | More | Full

Other Diffs

Ignore

Blank Lines Whitespace: Expand:

Diff

1.174
 
1.175
 
MAIN:ragge:20110324194714
 
cc.c
_>133133 char    *tmp3;
 134134 char    *tmp4;
 135135 char    *outfile, *ermfile;
<>136 -char *Bprefix(char *);
  136+static void add_prefix(const char *);
  137+static char *find_file(const char *, int);
137138 char *copy(char *, int);
 138139 char *setsuf(char *, char);
 139140 int getsuf(char *);
     
 !
198199 char    *pass0 = LIBEXECDIR COMPILER;
 199200 char    *as = ASSEMBLER;
 200201 char    *ld = LINKER;
<>201 -char    *Bflag;
  202+char    *sysroot;
202203 char *cppadd[] = CPPADD;
 203204 #ifdef DYNLINKER
 204205 char *dynlinker[] = DYNLINKER;
     
 !
364365                                 if (strcmp(argv[i], "--version") == 0) {
 365366                                         printf("%s\n", VERSSTR);
 366367                                         return 0;
<> 368+                                } else if (strncmp(argv[i], "--sysroot=", 10) == 0) {
  369+                                        sysroot = argv[i] + 10;
367370                                 } else if (strcmp(argv[i], "--param") == 0) {
 368371                                         /* NOTHING YET */;
 369372                                         i++; /* ignore arg */
     
 !
372375                                 break;
 373376 
 374377                         case 'B': /* other search paths for binaries */
<>375 -                                Bflag = &argv[i][2];
  378+                                add_prefix(argv[i] + 2);
376379                                 break;
 377380 
 378381 #ifdef MULTITARGET
     
 !
731734                         tmp3 = gettmp();
 732735                 tmp4 = gettmp();
 733736         }
<>734 -        if (Bflag) {
 735 -                altincdir = Bflag;
 736 -                pccincdir = Bflag;
 737 -                pcclibdir = Bflag;
 738 -        }
739737         if (signal(SIGINT, SIG_IGN) != SIG_IGN/* interrupt */
 740738                 signal(SIGINT, idexit);
 741739         if (signal(SIGTERM, SIG_IGN) != SIG_IGN)        /* terminate */
     
 !
10731071                 if (shared) {
 10741072                         if (!nostartfiles) {
 10751073                                 for (i = 0; startfiles_S[i]; i++)
<>1076 -                                        av[j++] = Bprefix(startfiles_S[i]);
  1074+                                        av[j++] = find_file(startfiles_S[i], R_OK);
10771075                         }
 10781076                 } else
 10791077 #endif
 10801078                 {
 10811079                         if (!nostartfiles) {
 10821080 #ifdef CRT0FILE_PROFILE
 10831081                                 if (pgflag) {
<>1084 -                                        av[j++] = Bprefix(crt0file_profile);
  1082+                                        av[j++] = find_file(crt0file_profile, R_OK);
10851083                                 } else
 10861084 #endif
 10871085                                 {
 10881086 #ifdef CRT0FILE
<>1089 -                                        av[j++] = Bprefix(crt0file);
  1087+                                        av[j++] = find_file(crt0file, R_OK);
10901088 #endif
 10911089                                 }
 10921090 #ifdef STARTFILES_T
 10931091                                 if (Bstatic) {
 10941092                                         for (i = 0; startfiles_T[i]; i++)
<>1095 -                                                av[j++] = Bprefix(startfiles_T[i]);
  1093+                                                av[j++] = find_file(startfiles_T[i], R_OK);
10961094                                 } else
 10971095 #endif
 10981096                                 {
 10991097 #ifdef STARTFILES
 11001098                                         for (i = 0; startfiles[i]; i++)
<>1101 -                                                av[j++] = Bprefix(startfiles[i]);
  1099+                                                av[j++] = find_file(startfiles[i], R_OK);
11021100 #endif
 11031101                                 }
 11041102                         }
     
 !
11421140 #endif
 11431141                         if (pgflag) {
 11441142                                 for (i = 0; libclibs_profile[i]; i++)
<>1145 -                                        av[j++] = Bprefix(libclibs_profile[i]);
  1143+                                        av[j++] = find_file(libclibs_profile[i], R_OK);
11461144                         } else {
 11471145                                 for (i = 0; libclibs[i]; i++)
<>1148 -                                        av[j++] = Bprefix(libclibs[i]);
  1146+                                        av[j++] = find_file(libclibs[i], R_OK);
11491147                         }
 11501148                 }
 11511149                 if (!nostartfiles) {
 11521150 #ifdef STARTFILES_S
 11531151                         if (shared) {
 11541152                                 for (i = 0; endfiles_S[i]; i++)
<>1155 -                                        av[j++] = Bprefix(endfiles_S[i]);
  1153+                                        av[j++] = find_file(endfiles_S[i], R_OK);
11561154                         } else
 11571155 #endif
 11581156                         {
 11591157 #ifdef STARTFILES_T
 11601158                                 if (Bstatic) {
 11611159                                         for (i = 0; endfiles_T[i]; i++)
<>1162 -                                                av[j++] = Bprefix(endfiles_T[i]);
  1160+                                                av[j++] = find_file(endfiles_T[i], R_OK);
11631161                                 } else
 11641162 #endif
 11651163                                 {
 11661164 #ifdef STARTFILES
 11671165                                         for (i = 0; endfiles[i]; i++)
<>1168 -                                                av[j++] = Bprefix(endfiles[i]);
  1166+                                                av[j++] = find_file(endfiles[i], R_OK);
11691167 #endif
 11701168                                 }
 11711169                         }
     
 !
12481246         dexit(eval);
 12491247 }
 12501248 
<>1251 -char *
 1252 -Bprefix(char *s)
  1249+static size_t file_prefixes_cnt;
  1250+static char **file_prefixes;
  1251+
  1252+static void
  1253+add_prefix(const char *prefix)
12531254 {
<>1254 -        char *suffix;
 1255 -        char *str;
 1256 -        int i;
  1255+        file_prefixes = realloc(file_prefixes,
  1256+            sizeof(*file_prefixes) * file_prefixes_cnt);
  1257+        if (file_prefixes == NULL) {
  1258+                error("malloc failed");
  1259+                exit(1);
  1260+        }
  1261+        if ((file_prefixes[file_prefixes_cnt++] = strdup(prefix)) == NULL) {
  1262+                error("malloc failed");
  1263+                exit(1);
  1264+        }
  1265+}
12571266 
<>1258 -#ifdef WIN32
  1267+static char *
  1268+find_file(const char *base, int mode)
  1269+{
  1270+        char *path;
  1271+        size_t baselen = strlen(base);
  1272+        size_t sysrootlen = sysroot ? strlen(sysroot) : 0;
  1273+        size_t len, prefix_len, i;
12591274 
<>1260 -        /*  put here to save sprinkling it ~everywhere  */
 1261 -        swin32pathsubst(s);
  1275+        for (i = 0; i < file_prefixes_cnt; ++i) {
  1276+                prefix_len = strlen(file_prefixes[i]);
  1277+                len = prefix_len + + baselen + 2;
  1278+                if (file_prefixes[i][0] == '=') {
  1279+                        len += sysrootlen;
  1280+                        path = malloc(len);
  1281+                        snprintf(path, len, "%s%s/%s", sysroot,
  1282+                            file_prefixes[i] + 1, base);
  1283+                } else {
  1284+                        path = malloc(len);
  1285+                        snprintf(path, len, "%s/%s", file_prefixes[i], base);
  1286+                }
  1287+                if (access(path, mode) == 0)
  1288+                        return path;
  1289+                free(path);
  1290+        }
12621291 
<>1263 -        if (Bflag == NULL)
 1264 -                return s;
 1265 -        suffix = strrchr(s, '/');
 1266 -        if (suffix == NULL)
 1267 -                suffix = strrchr(s, '\\');
 1268 -
 1269 -#else
 1270 -
 1271 -        if (Bflag == NULL || s[0] != '/')
 1272 -                return s;
 1273 -        suffix = strrchr(s, '/');
 1274 -
 1275 -#endif
 1276 -
 1277 -        if (suffix == NULL)
 1278 -                suffix = s;
 1279 -
 1280 -        str = copy(Bflag, i = strlen(suffix));
 1281 -        strlcat(str, suffix, strlen(Bflag) + i + 1);
 1282 -        return str;
  1292+        path = strdup(base);
  1293+        if (path == NULL) {
  1294+                error("malloc failed");
  1295+                exit(1);
  1296+        }
  1297+        return path;
12831298 }
 12841299 
 12851300 int
     
 !
13601375 {
 13611376         int t, status = 0;
 13621377         pid_t p;
<>1363 -        char *s;
 1364 -        char * volatile a = NULL;
 1365 -        volatile size_t len;
  1378+        char *prog;
13661379 
 13671380         if (vflag) {
 13681381                 fprintf(stderr, "%s ", f);
     
 !
13711384                 fprintf(stderr, "\n");
 13721385         }
 13731386 
<>1374 -        if (Bflag) {
 1375 -                len = strlen(Bflag) + 8;
 1376 -                a = malloc(len);
 1377 -        }
  1387+        prog = find_file(f, X_OK);
13781388 #ifdef HAVE_VFORK
 13791389         if ((p = vfork()) == 0) {
 13801390 #else
 13811391         if ((p = fork()) == 0) {
 13821392 #endif
<>1383 -                if (Bflag) {
 1384 -                        if (a == NULL) {
 1385 -                                error("callsys: malloc failed");
 1386 -                                exit(1);
 1387 -                        }
 1388 -                        if ((s = strrchr(f, '/'))) {
 1389 -                                strlcpy(a, Bflag, len);
 1390 -                                strlcat(a, s, len);
 1391 -                                execv(a, v);
 1392 -                        }
 1393 -                }
 1394 -                execvp(f, v);
 1395 -                if ((s = strrchr(f, '/')))
 1396 -                        execvp(s+1, v);
 1397 -                fprintf(stderr, "Can't find %s\n", f);
  1393+                static const char msg[] = "Can't find ";
  1394+                execvp(prog, v);
  1395+                (void)write(STDERR_FILENO, msg, sizeof(msg));
  1396+                (void)write(STDERR_FILENO, prog, strlen(prog));
  1397+                (void)write(STDERR_FILENO, "\n", 1);
13981398                 _exit(100);
 13991399         }
 14001400         if (p == -1) {
 14011401                 fprintf(stderr, "fork() failed, try again\n");
 14021402                 return(100);
 14031403         }
<>1404 -        if (Bflag) {
 1405 -                free(a);
 1406 -        }
  1404+        free(prog);
<_14071405         while (waitpid(p, &status, 0) == -1 && errno == EINTR)
 14081406                 ;
 14091407         if (WIFEXITED(status))
FishEye: Open Source License registered to PCC.
Atlassian FishEye, CVS analysis. (Version:1.6.3 Build:build-336 2008-11-04) - Administration - Page generated 2014-12-29 16:55 +0100