Print this page
jlevon comments

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/cw/cw.c
          +++ new/usr/src/tools/cw/cw.c
↓ open down ↓ 586 lines elided ↑ open up ↑
 587  587  
 588  588          (void) asprintf(&ret, "%s/%s%s", ctx->i_tmpdir, tmpl,
 589  589              (ext != NULL) ? ext : "");
 590  590  
 591  591          if (ret == NULL)
 592  592                  nomem();
 593  593  
 594  594          return (ret);
 595  595  }
 596  596  
      597 +static boolean_t
      598 +is_source_file(const char *path)
      599 +{
      600 +        char *ext = strrchr(path, '.');
      601 +
      602 +        if ((ext == NULL) || ((ext + 1) == '\0'))
      603 +                return (B_FALSE);
      604 +
      605 +        ext += 1;
      606 +
      607 +        if ((strcasecmp(ext, "c") == 0) ||
      608 +            (strcmp(ext, "cc") == 0) ||
      609 +            (strcmp(ext, "i") == 0) ||
      610 +            (strcasecmp(ext, "s") == 0) ||
      611 +            (strcmp(ext, "cpp") == 0)) {
      612 +                return (B_TRUE);
      613 +        }
      614 +
      615 +        return (B_FALSE);
      616 +}
      617 +
      618 +
 597  619  static void
 598  620  do_gcc(cw_ictx_t *ctx)
 599  621  {
 600  622          int c;
 601  623          int nolibc = 0;
 602  624          int in_output = 0, seen_o = 0, c_files = 0;
 603  625          cw_op_t op = CW_O_LINK;
 604  626          char *model = NULL;
 605  627          char *nameflag;
 606  628          int mflag = 0;
↓ open down ↓ 45 lines elided ↑ open up ↑
 652  674                  if (*arg == '-') {
 653  675                          arglen--;
 654  676                  } else {
 655  677                          /*
 656  678                           * Discard inline files that gcc doesn't grok
 657  679                           */
 658  680                          if (!in_output && arglen > 3 &&
 659  681                              strcmp(arg + arglen - 3, ".il") == 0)
 660  682                                  continue;
 661  683  
 662      -                        if (!in_output && arglen > 2 &&
 663      -                            arg[arglen - 2] == '.' &&
 664      -                            (arg[arglen - 1] == 'S' || arg[arglen - 1] == 's' ||
 665      -                            arg[arglen - 1] == 'c' || arg[arglen - 1] == 'i'))
      684 +                        if (!in_output && is_source_file(arg))
 666  685                                  c_files++;
 667  686  
 668  687                          /*
 669  688                           * Otherwise, filenames and partial arguments
 670  689                           * are passed through for gcc to chew on.  However,
 671  690                           * output is always discarded for the secondary
 672  691                           * compiler.
 673  692                           */
 674  693                          if ((ctx->i_flags & CW_F_SHADOW) && in_output) {
 675  694                                  newae(ctx->i_ae, discard_file_name(ctx, arg));
↓ open down ↓ 683 lines elided ↑ open up ↑
1359 1378          if (ctx->i_flags & CW_F_PROG) {
1360 1379                  newae(ctx->i_ae, "-V");
1361 1380                  return;
1362 1381          }
1363 1382  
1364 1383          if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->c_name) == -1)
1365 1384                  nomem();
1366 1385  
1367 1386          while (--ctx->i_oldargc > 0) {
1368 1387                  char *arg = *++ctx->i_oldargv;
1369      -                size_t arglen = strlen(arg);
1370 1388  
1371 1389                  if (strncmp(arg, "-_CC=", 5) == 0) {
1372 1390                          newae(ctx->i_ae, strchr(arg, '=') + 1);
1373 1391                          continue;
1374 1392                  }
1375 1393  
1376 1394                  if (*arg != '-') {
1377      -                        if (!in_output && arglen > 2 &&
1378      -                            arg[arglen - 2] == '.' &&
1379      -                            (arg[arglen - 1] == 'S' || arg[arglen - 1] == 's' ||
1380      -                            arg[arglen - 1] == 'c' || arg[arglen - 1] == 'i'))
     1395 +                        if (!in_output && is_source_file(arg))
1381 1396                                  c_files++;
1382 1397  
1383 1398                          if (in_output == 0 || !(ctx->i_flags & CW_F_SHADOW)) {
1384 1399                                  newae(ctx->i_ae, arg);
1385 1400                          } else {
1386 1401                                  in_output = 0;
1387 1402                                  newae(ctx->i_ae, discard_file_name(ctx, arg));
1388 1403                          }
1389 1404                          continue;
1390 1405                  }
↓ open down ↓ 280 lines elided ↑ open up ↑
1671 1686                  } else {
1672 1687                          return;
1673 1688                  }
1674 1689          }
1675 1690  
1676 1691          errno = 0;
1677 1692          while ((dp = readdir(dirp)) != NULL) {
1678 1693                  (void) snprintf(buf, MAXPATHLEN, "%s/%s", ctx->i_tmpdir,
1679 1694                      dp->d_name);
1680 1695  
1681      -                if (strncmp(dp->d_name, ".", strlen(dp->d_name)) == 0 ||
1682      -                    strncmp(dp->d_name, "..", strlen(dp->d_name)) == 0)
     1696 +                if (strcmp(dp->d_name, ".") == 0 ||
     1697 +                    strcmp(dp->d_name, "..") == 0) {
1683 1698                          continue;
     1699 +                }
1684 1700  
1685 1701                  if (unlink(buf) == -1)
1686 1702                          err(1, "failed to unlink temp file: %s", dp->d_name);
1687 1703                  errno = 0;
1688 1704          }
1689 1705  
1690 1706          if (errno != 0) {
1691 1707                  err(1, "failed to read temporary directory: %s",
1692 1708                      ctx->i_tmpdir);
1693 1709          }
↓ open down ↓ 154 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX