]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/ccanlint.c
ccanlint: chdir to temporary dir so gcov files land there.
[ccan] / tools / ccanlint / ccanlint.c
index 3555ad2a09d1ea083c1fba68aafbaed98f24cbc1..d65a4a43a7412632f6cbcfa0d0301f8c818d0cfe 100644 (file)
@@ -333,7 +333,7 @@ int main(int argc, char *argv[])
        unsigned int score = 0, total_score = 0;
        struct manifest *m;
        struct ccanlint *i;
-       const char *prefix = "", *dir = ".";
+       const char *prefix = "", *dir = talloc_getcwd(NULL);
        
        init_tests();
 
@@ -344,7 +344,11 @@ int main(int argc, char *argv[])
        while ((c = getopt(argc, argv, "sd:vnlx:t:k:")) != -1) {
                switch (c) {
                case 'd':
-                       dir = optarg;
+                       if (optarg[0] != '/')
+                               dir = talloc_asprintf_append(NULL, "%s/%s",
+                                                            dir, optarg);
+                       else
+                               dir = optarg;
                        prefix = talloc_append_string(talloc_basename(NULL,
                                                                      optarg),
                                                      ": ");
@@ -383,6 +387,10 @@ int main(int argc, char *argv[])
        if (optind < argc)
                usage(argv[0]);
 
+       /* We move into temporary directory, so gcov dumps its files there. */
+       if (chdir(temp_dir(talloc_autofree_context())) != 0)
+               err(1, "Error changing to %s temporary dir", temp_dir(NULL));
+
        m = get_manifest(talloc_autofree_context(), dir);
 
        /* If you don't pass the compulsory tests, you don't even get a score */