Throw an exception when the current working directory can not be retrieved
This commit is contained in:
@@ -23,6 +23,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <simgear/misc/sg_dir.hxx>
|
#include <simgear/misc/sg_dir.hxx>
|
||||||
|
#include <simgear/structure/exception.hxx>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
@@ -83,13 +84,17 @@ void Dir::setRemoveOnDestroy()
|
|||||||
_removeOnDestroy = true;
|
_removeOnDestroy = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
Dir Dir::current()
|
Dir Dir::current()
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
char* buf = _getcwd(NULL, 0);
|
char* buf = _getcwd(NULL, 0);
|
||||||
#else
|
#else
|
||||||
char* buf = ::getcwd(NULL, 0);
|
char *buf = ::getcwd(NULL, 0);
|
||||||
#endif
|
#endif
|
||||||
|
if (!buf && errno == 2) sg_exception("The current directory is invalid");
|
||||||
|
else throw sg_exception(strerror(errno));
|
||||||
|
|
||||||
SGPath p(buf);
|
SGPath p(buf);
|
||||||
free(buf);
|
free(buf);
|
||||||
return Dir(p);
|
return Dir(p);
|
||||||
|
|||||||
Reference in New Issue
Block a user