Print this page
jlevon comments

@@ -592,10 +592,32 @@
                 nomem();
 
         return (ret);
 }
 
+static boolean_t
+is_source_file(const char *path)
+{
+        char *ext = strrchr(path, '.');
+
+        if ((ext == NULL) || ((ext + 1) == '\0'))
+                return (B_FALSE);
+
+        ext += 1;
+
+        if ((strcasecmp(ext, "c") == 0) ||
+            (strcmp(ext, "cc") == 0) ||
+            (strcmp(ext, "i") == 0) ||
+            (strcasecmp(ext, "s") == 0) ||
+            (strcmp(ext, "cpp") == 0)) {
+                return (B_TRUE);
+        }
+
+        return (B_FALSE);
+}
+
+
 static void
 do_gcc(cw_ictx_t *ctx)
 {
         int c;
         int nolibc = 0;

@@ -657,14 +679,11 @@
                          */
                         if (!in_output && arglen > 3 &&
                             strcmp(arg + arglen - 3, ".il") == 0)
                                 continue;
 
-                        if (!in_output && arglen > 2 &&
-                            arg[arglen - 2] == '.' &&
-                            (arg[arglen - 1] == 'S' || arg[arglen - 1] == 's' ||
-                            arg[arglen - 1] == 'c' || arg[arglen - 1] == 'i'))
+                        if (!in_output && is_source_file(arg))
                                 c_files++;
 
                         /*
                          * Otherwise, filenames and partial arguments
                          * are passed through for gcc to chew on.  However,

@@ -1364,22 +1383,18 @@
         if (asprintf(&nameflag, "-_%s=", ctx->i_compiler->c_name) == -1)
                 nomem();
 
         while (--ctx->i_oldargc > 0) {
                 char *arg = *++ctx->i_oldargv;
-                size_t arglen = strlen(arg);
 
                 if (strncmp(arg, "-_CC=", 5) == 0) {
                         newae(ctx->i_ae, strchr(arg, '=') + 1);
                         continue;
                 }
 
                 if (*arg != '-') {
-                        if (!in_output && arglen > 2 &&
-                            arg[arglen - 2] == '.' &&
-                            (arg[arglen - 1] == 'S' || arg[arglen - 1] == 's' ||
-                            arg[arglen - 1] == 'c' || arg[arglen - 1] == 'i'))
+                        if (!in_output && is_source_file(arg))
                                 c_files++;
 
                         if (in_output == 0 || !(ctx->i_flags & CW_F_SHADOW)) {
                                 newae(ctx->i_ae, arg);
                         } else {

@@ -1676,13 +1691,14 @@
         errno = 0;
         while ((dp = readdir(dirp)) != NULL) {
                 (void) snprintf(buf, MAXPATHLEN, "%s/%s", ctx->i_tmpdir,
                     dp->d_name);
 
-                if (strncmp(dp->d_name, ".", strlen(dp->d_name)) == 0 ||
-                    strncmp(dp->d_name, "..", strlen(dp->d_name)) == 0)
+                if (strcmp(dp->d_name, ".") == 0 ||
+                    strcmp(dp->d_name, "..") == 0) {
                         continue;
+                }
 
                 if (unlink(buf) == -1)
                         err(1, "failed to unlink temp file: %s", dp->d_name);
                 errno = 0;
         }