1 #define _FILE_OFFSET_BITS 64
5 #include <msp/core/systemerror.h>
7 #include "stat_private.h"
12 Stat::Private::Private(const Private &other):
13 owner_id(other.owner_id),
14 group_id(other.group_id)
17 Stat::Private::~Private()
20 Stat Stat::Private::from_struct_stat(const struct stat &st)
24 if(S_ISREG(st.st_mode))
25 result.type = REGULAR;
26 else if(S_ISDIR(st.st_mode))
27 result.type = DIRECTORY;
28 else if(S_ISLNK(st.st_mode))
29 result.type = SYMLINK;
31 result.type = UNKNOWN;
32 result.size = st.st_size;
33 result.alloc_size = st.st_blocks*512;
34 result.mtime = Time::TimeStamp::from_unixtime(st.st_mtime);
36 result.priv = new Private;
37 result.priv->owner_id = st.st_uid;
38 result.priv->group_id = st.st_gid;
44 Stat Stat::stat(const Path &path)
47 int ret = ::stat(path.str().c_str(), &st);
53 throw system_error("stat");
56 return Private::from_struct_stat(st);
59 Stat Stat::lstat(const Path &path)
62 int ret = ::lstat(path.str().c_str(), &st);
68 throw system_error("lstat");
71 return Private::from_struct_stat(st);
74 bool exists(const Path &path)
76 return access(path.str().c_str(), F_OK)==0;