X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Futils.cpp;h=45cd614b150ccaaea463f3c9860dabbe3bc82e1d;hb=92eb9e8756f0eb85bbefac59cc8cfbfc914b70f7;hp=204f33bfdedcf841e6b4b4e0e090d9caa1824d67;hpb=bfbb7edfb2ae76d23f26e0b22787617ff621747d;p=libs%2Fcore.git diff --git a/source/utils.cpp b/source/utils.cpp index 204f33b..45cd614 100644 --- a/source/utils.cpp +++ b/source/utils.cpp @@ -55,6 +55,14 @@ Path fix_case(const Path &path) return result; } +/** +Creates the given directory and any parent directories if needed. + +@param path The path to create +@param mode Access mode for new directories + +@return 0 on success, -1 on error +*/ int mkpath(const Path &path, int mode) { Path p; @@ -173,5 +181,18 @@ Path relative(const Path &path, const Path &base) return result; } +/** +Extracts the basename from the given path. Same thing as Path::Path(p)[-1], +but faster. +*/ +string basename(const std::string &p) +{ + unsigned slash=p.rfind(DIRCHAR); + if(slash==string::npos) + return p; + else + return p.substr(slash+1); +} + } // namespace Path } // namespace Msp