]> git.mxchange.org Git - simgear.git/commitdiff
Throw an exception when the current working directory can not be retrieved
authorErik Hofman <erik@ehofman.com>
Tue, 7 Jun 2016 09:51:28 +0000 (11:51 +0200)
committerRoland Haeder <roland@mxchange.org>
Sat, 13 Aug 2016 08:21:16 +0000 (10:21 +0200)
simgear/misc/sg_dir.cxx

index 68916f048d4da0822396b994406c8fa41c833e15..ce69b4ac68f731cf0ec5a24e6fc38b0db95695d5 100644 (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
-    charbuf = ::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);