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);