Throw an exception when the current working directory can not be retrieved

This commit is contained in:
Erik Hofman
2016-06-07 11:51:28 +02:00
parent cb80af0ebe
commit dc1696dfd5

View File

@@ -23,6 +23,7 @@
#endif
#include <simgear/misc/sg_dir.hxx>
#include <simgear/structure/exception.hxx>
#include <math.h>
#include <stdlib.h>
#include <cstdio>
@@ -83,13 +84,17 @@ void Dir::setRemoveOnDestroy()
_removeOnDestroy = true;
}
#include <stdio.h>
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);