#include <cerrno>
#include <unistd.h>
#include <sys/stat.h>
-#include <grp.h>
-#include <pwd.h>
#include <msp/core/systemerror.h>
#include <msp/strings/format.h>
#include "stat.h"
return result;
}
-void Stat::Private::fill_owner_info(Stat::OwnerInfo &result)
-{
- char buf[1024];
-
- struct passwd pw;
- struct passwd *owner;
- if(!getpwuid_r(owner_id, &pw, buf, sizeof(buf), &owner) && owner)
- result.owner = owner->pw_name;
- else
- result.owner = format("%d", owner_id);
-
- struct group gr;
- struct group *group;
- if(!getgrgid_r(group_id, &gr, buf, sizeof(buf), &group) && group)
- result.group = group->gr_name;
- else
- result.group = format("%d", group_id);
-}
-
Stat Stat::stat(const Path &path)
{
int ret = ::stat(path.str().c_str(), &st);
if(ret==-1)
{
- if(errno==ENOENT)
+ int err = errno;
+ if(err==ENOENT)
return Stat();
else
- throw system_error("stat");
+ throw system_error(format("stat(%s)", path), err);
}
return Private::from_struct_stat(st);
int ret = ::lstat(path.str().c_str(), &st);
if(ret==-1)
{
- if(errno==ENOENT)
+ int err = errno;
+ if(err==ENOENT)
return Stat();
else
- throw system_error("lstat");
+ throw system_error(format("lstat(%s)", path), err);
}
return Private::from_struct_stat(st);