]> git.tdb.fi Git - libs/core.git/blob - source/fs/stat.cpp
Remove Id tags and copyright notices from source files
[libs/core.git] / source / fs / stat.cpp
1 #include <cerrno>
2 #ifdef WIN32
3 #include <io.h>
4 #endif
5 #include <msp/core/except.h>
6 #include "path.h"
7 #include "stat.h"
8
9 namespace Msp {
10 namespace FS {
11
12 int stat(const Path &fn, struct stat &st)
13 {
14         return ::stat(fn.str().c_str(), &st);
15 }
16
17 struct stat stat(const Path &fn)
18 {
19         struct stat st;
20         if(stat(fn, st)==-1)
21                 throw SystemError("stat failed", errno);
22         return st;
23 }
24
25 int lstat(const Path &fn, struct stat &st)
26 {
27 #ifdef WIN32
28         return stat(fn, st);
29 #else
30         return ::lstat(fn.str().c_str(), &st);
31 #endif
32 }
33
34 struct stat lstat(const Path &fn)
35 {
36         struct stat st;
37         if(lstat(fn, st)==-1)
38                 throw SystemError("lstat failed", errno);
39         return st;
40 }
41
42 bool exists(const Path &path)
43 {
44         return access(path.str().c_str(), F_OK)==0;
45 }
46
47 bool is_reg(const Path &path)
48 {
49         struct stat st;
50         if(stat(path, st)==0)
51                 return S_ISREG(st.st_mode);
52         return false;
53 }
54
55 bool is_dir(const Path &path)
56 {
57         struct stat st;
58         if(stat(path, st)==0)
59                 return S_ISDIR(st.st_mode);
60         return false;
61 }
62
63 bool is_link(const Path &path)
64 {
65 #ifdef WIN32
66         (void)path;
67 #else
68         struct stat st;
69         if(lstat(path, st)==0)
70                 return S_ISLNK(st.st_mode);
71 #endif
72         return false;
73 }
74
75 } // namespace FS
76 } // namespace Msp