X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Futils.cpp;h=d9522a3c6551d264ccf9896ef780b340220a99ef;hp=acf7dcd1f66516a04ca8fdc928dc1ee0da4f513c;hb=59db379f143f9accda21b831e0243d02f27c1c70;hpb=0ba3e9d15af4e8c30eef5445d2b64fee4870505f diff --git a/source/utils.cpp b/source/utils.cpp index acf7dcd..d9522a3 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -7,7 +7,7 @@ Distributed under the LGPL #include #include -#include +#include #ifndef WIN32 #include #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,22 @@ 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 +} + +void chdir(const Path &path) +{ + if(::chdir(path.str().c_str())==-1) + throw SystemError("chdir failed", errno); +} + } // namespace Msp