X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fstat.cpp;fp=source%2Fstat.cpp;h=5a0ee45ba20fe92e029ad2aa5ab73d089fd3f71c;hb=f91f1df3e0b00b3a270e571d4b2c8251da4d1226;hp=0000000000000000000000000000000000000000;hpb=e6fec68039fb5212993d687d352c540e407e6d96;p=libs%2Fcore.git diff --git a/source/stat.cpp b/source/stat.cpp new file mode 100644 index 0000000..5a0ee45 --- /dev/null +++ b/source/stat.cpp @@ -0,0 +1,43 @@ +/* $Id$ + +This file is part of libmspfs +Copyright © 2006-2008 Mikko Rasa, Mikkosoft Productions +Distributed under the LGPL +*/ + +#include +#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; +} + +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; +} + +} // namespace FS +} // namespace Msp