]> git.tdb.fi Git - libs/core.git/blob - source/stat.cpp
Refactor the API
[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 #ifdef WIN32
10 #include <io.h>
11 #endif
12 #include <msp/core/except.h>
13 #include "path.h"
14 #include "stat.h"
15
16 namespace Msp {
17 namespace FS {
18
19 int stat(const Path &fn, struct stat &st)
20 {
21         return ::stat(fn.str().c_str(), &st);
22 }
23
24 struct stat stat(const Path &fn)
25 {
26         struct stat st;
27         if(stat(fn, st)==-1)
28                 throw SystemError("stat failed", errno);
29         return st;
30 }
31
32 bool exists(const Path &path)
33 {
34         return access(path.str().c_str(), F_OK)==0;
35 }
36
37 bool is_reg(const Path &path)
38 {
39         struct stat st;
40         if(stat(path, st)==0)
41                 return S_ISREG(st.st_mode);
42         return false;
43 }
44
45 bool is_dir(const Path &path)
46 {
47         struct stat st;
48         if(stat(path, st)==0)
49                 return S_ISDIR(st.st_mode);
50         return false;
51 }
52
53 } // namespace FS
54 } // namespace Msp