1 #define _FILE_OFFSET_BITS 64
5 #include <msp/core/systemerror.h>
6 #include <msp/strings/format.h>
8 #include "stat_private.h"
13 Stat::Private::Private(const Private &other):
14 owner_id(other.owner_id),
15 group_id(other.group_id)
18 Stat::Private::~Private()
21 Stat Stat::Private::from_struct_stat(const struct stat &st)
25 if(S_ISREG(st.st_mode))
26 result.type = REGULAR;
27 else if(S_ISDIR(st.st_mode))
28 result.type = DIRECTORY;
29 else if(S_ISLNK(st.st_mode))
30 result.type = SYMLINK;
32 result.type = UNKNOWN;
33 result.size = st.st_size;
34 result.alloc_size = st.st_blocks*512;
35 result.mtime = Time::TimeStamp::from_unixtime(st.st_mtime);
37 result.priv = new Private;
38 result.priv->owner_id = st.st_uid;
39 result.priv->group_id = st.st_gid;
45 Stat Stat::stat(const Path &path)
48 int ret = ::stat(path.str().c_str(), &st);
55 throw system_error(format("stat(%s)", path), err);
58 return Private::from_struct_stat(st);
61 Stat Stat::lstat(const Path &path)
64 int ret = ::lstat(path.str().c_str(), &st);
71 throw system_error(format("lstat(%s)", path), err);
74 return Private::from_struct_stat(st);
77 bool exists(const Path &path)
79 return access(path.str().c_str(), F_OK)==0;