From 478c2b2e88423b31550a404ce369561835d01d9b Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Tue, 7 Jun 2016 11:51:28 +0200 Subject: [PATCH] Throw an exception when the current working directory can not be retrieved --- simgear/misc/sg_dir.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/simgear/misc/sg_dir.cxx b/simgear/misc/sg_dir.cxx index 68916f04..ce69b4ac 100644 --- a/simgear/misc/sg_dir.cxx +++ b/simgear/misc/sg_dir.cxx @@ -23,6 +23,7 @@ #endif #include +#include #include #include #include @@ -83,13 +84,17 @@ void Dir::setRemoveOnDestroy() _removeOnDestroy = true; } +#include Dir Dir::current() { #ifdef _WIN32 char* buf = _getcwd(NULL, 0); #else - char* buf = ::getcwd(NULL, 0); + char *buf = ::getcwd(NULL, 0); #endif + if (!buf && errno == 2) sg_exception("The current directory is invalid"); + else throw sg_exception(strerror(errno)); + SGPath p(buf); free(buf); return Dir(p); -- 2.39.5