]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/unix/stat.cpp
Include filename in errors from stat
[libs/core.git] / source / fs / unix / stat.cpp
index 1404fede5c030b462fa410c38adb9de0dd0cb568..352363316f5bf47a1739451a44c92c78da257c2e 100644 (file)
@@ -2,8 +2,6 @@
 #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"
@@ -43,25 +41,6 @@ Stat Stat::Private::from_struct_stat(const struct stat &st)
        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)
 {
@@ -69,10 +48,11 @@ 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);
@@ -84,10 +64,11 @@ Stat Stat::lstat(const Path &path)
        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);