From: Erik Hofman Date: Tue, 7 Jun 2016 09:51:28 +0000 (+0200) Subject: Throw an exception when the current working directory can not be retrieved X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=478c2b2e88423b31550a404ce369561835d01d9b;p=simgear.git Throw an exception when the current working directory can not be retrieved --- 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);