X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Fstat.cpp;h=1dc46db78289dce316ffb36bee60b3a9539066e2;hp=5a0ee45ba20fe92e029ad2aa5ab73d089fd3f71c;hb=fa77438b62207466c48620604c8cc34931080936;hpb=f91f1df3e0b00b3a270e571d4b2c8251da4d1226 diff --git a/source/stat.cpp b/source/stat.cpp index 5a0ee45..1dc46db 100644 --- a/source/stat.cpp +++ b/source/stat.cpp @@ -6,6 +6,9 @@ Distributed under the LGPL */ #include +#ifdef WIN32 +#include +#endif #include #include "path.h" #include "stat.h" @@ -26,11 +29,36 @@ struct stat stat(const Path &fn) return st; } +int lstat(const Path &fn, struct stat &st) +{ +#ifdef WIN32 + return stat(fn, st); +#else + return ::lstat(fn.str().c_str(), &st); +#endif +} + +struct stat lstat(const Path &fn) +{ + struct stat st; + if(lstat(fn, st)==-1) + throw SystemError("lstat failed", errno); + return st; +} + bool exists(const Path &path) { return access(path.str().c_str(), F_OK)==0; } +bool is_reg(const Path &path) +{ + struct stat st; + if(stat(path, st)==0) + return S_ISREG(st.st_mode); + return false; +} + bool is_dir(const Path &path) { struct stat st; @@ -39,5 +67,17 @@ bool is_dir(const Path &path) return false; } +bool is_link(const Path &path) +{ +#ifdef WIN32 + (void)path; +#else + struct stat st; + if(lstat(path, st)==0) + return S_ISLNK(st.st_mode); +#endif + return false; +} + } // namespace FS } // namespace Msp