summaryrefslogtreecommitdiff
path: root/ccache.c
diff options
context:
space:
mode:
authorJoel Rosdahl <joel@rosdahl.net>2012-01-16 22:35:39 +0100
committerJoel Rosdahl <joel@rosdahl.net>2012-01-16 22:35:39 +0100
commite74b07331ecc57ee9be68a5f09cdb6447215e56c (patch)
tree4c5fa392eeeda41991f58dc64b3330bde895fd24 /ccache.c
parent7633687271ed821461e799a6d41822179bf431f1 (diff)
downloadccache-e74b07331ecc57ee9be68a5f09cdb6447215e56c.tar.gz
Don't crash when current working directory doesn't exist
Diffstat (limited to 'ccache.c')
-rw-r--r--ccache.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/ccache.c b/ccache.c
index e41af135..d89c076d 100644
--- 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);