X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ffs%2Fstat.cpp;fp=source%2Ffs%2Fstat.cpp;h=1dc46db78289dce316ffb36bee60b3a9539066e2;hp=0000000000000000000000000000000000000000;hb=af94bc926e301e9b871dc18662b4fa6e5614fdbf;hpb=fa77438b62207466c48620604c8cc34931080936 diff --git a/source/fs/stat.cpp b/source/fs/stat.cpp new file mode 100644 index 0000000..1dc46db --- /dev/null +++ b/source/fs/stat.cpp @@ -0,0 +1,83 @@ +/* $Id$ + +This file is part of libmspfs +Copyright © 2006-2008 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include +#ifdef WIN32 +#include +#endif +#include +#include "path.h" +#include "stat.h" + +namespace Msp { +namespace FS { + +int stat(const Path &fn, struct stat &st) +{ + return ::stat(fn.str().c_str(), &st); +} + +struct stat stat(const Path &fn) +{ + struct stat st; + if(stat(fn, st)==-1) + throw SystemError("stat failed", errno); + 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; + if(stat(path, st)==0) + return S_ISDIR(st.st_mode); + 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