]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Don't crash when current working directory doesn't exist
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 16 Jan 2012 21:35:39 +0000 (22:35 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 16 Jan 2012 21:35:39 +0000 (22:35 +0100)
ccache.c

index e41af13557fa946f6397ecb71ba3f63260ab0e7a..d89c076d1ed52df9f020c4e8c493d2557fa902cb 100644 (file)
--- a/ccache.c
+++ b/ccache.c
@@ -392,6 +392,15 @@ make_relative_path(char *path)
                return path;
        }
 
+       if (!current_working_dir) {
+               current_working_dir = get_cwd();
+               if (!current_working_dir) {
+                       cc_log("Unable to determine current working directory: %s",
+                              strerror(errno));
+                       failed();
+               }
+       }
+
        relpath = get_relative_path(current_working_dir, path);
        free(path);
        return relpath;
@@ -2160,11 +2169,6 @@ ccache_main(int argc, char *argv[])
                }
        }
 
-       current_working_dir = get_cwd();
-       if (!current_working_dir) {
-               cc_log("Could not determine current working directory");
-               failed();
-       }
        cache_dir = getenv("CCACHE_DIR");
        if (cache_dir) {
                cache_dir = x_strdup(cache_dir);