From e74b07331ecc57ee9be68a5f09cdb6447215e56c Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Mon, 16 Jan 2012 22:35:39 +0100 Subject: Don't crash when current working directory doesn't exist --- ccache.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'ccache.c') 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); -- cgit v1.2.1