]> git.tdb.fi Git - libs/core.git/blobdiff - source/utils.cpp
Add is_dir and get_home_dir functions
[libs/core.git] / source / utils.cpp
index acf7dcd1f66516a04ca8fdc928dc1ee0da4f513c..18784b3a423bb8b5d165c79ef95d72db0d594877 100644 (file)
@@ -7,7 +7,7 @@ Distributed under the LGPL
 
 #include <dirent.h>
 #include <errno.h>
-#include <msp/core/error.h>
+#include <msp/core/except.h>
 #ifndef WIN32
 #include <fnmatch.h>
 #else
@@ -158,6 +158,14 @@ bool exists(const Path &path)
        return access(path.str().c_str(), F_OK)==0;
 }
 
+bool is_dir(const Path &path)
+{
+       struct stat st;
+       if(stat(path, st)==0)
+               return S_ISDIR(st.st_mode);
+       return false;
+}
+
 Filename splitext(const string &fn)
 {
        Filename result;
@@ -224,4 +232,16 @@ Path getcwd()
        return ::getcwd(buf, sizeof(buf));
 }
 
+Path get_home_dir()
+{
+#ifndef WIN32
+       const char *home=getenv("HOME");
+       if(home)
+               return home;
+       return ".";
+#else
+       return ".";
+#endif
+}
+
 } // namespace Msp