]> git.tdb.fi Git - libs/core.git/blob - source/stat.cpp
5a0ee45ba20fe92e029ad2aa5ab73d089fd3f71c
[libs/core.git] / source / stat.cpp
1 /* $Id$
2
3 This file is part of libmspfs
4 Copyright © 2006-2008  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #include <cerrno>
9 #include <msp/core/except.h>
10 #include "path.h"
11 #include "stat.h"
12
13 namespace Msp {
14 namespace FS {
15
16 int stat(const Path &fn, struct stat &st)
17 {
18         return ::stat(fn.str().c_str(), &st);
19 }
20
21 struct stat stat(const Path &fn)
22 {
23         struct stat st;
24         if(stat(fn, st)==-1)
25                 throw SystemError("stat failed", errno);
26         return st;
27 }
28
29 bool exists(const Path &path)
30 {
31         return access(path.str().c_str(), F_OK)==0;
32 }
33
34 bool is_dir(const Path &path)
35 {
36         struct stat st;
37         if(stat(path, st)==0)
38                 return S_ISDIR(st.st_mode);
39         return false;
40 }
41
42 } // namespace FS
43 } // namespace Msp