]> git.tdb.fi Git - libs/core.git/blob - source/fs/unix/stat_owner.cpp
Fix a shadowed variable warning
[libs/core.git] / source / fs / unix / stat_owner.cpp
1 #include <grp.h>
2 #include <pwd.h>
3 #include <msp/strings/format.h>
4 #include "stat.h"
5 #include "stat_private.h"
6
7 namespace Msp {
8 namespace FS {
9
10 void Stat::Private::fill_owner_info(Stat::OwnerInfo &result)
11 {
12         char buf[1024];
13
14         if(owner_id!=INVALID_UID)
15         {
16                 struct passwd pw;
17                 struct passwd *owner;
18                 if(!getpwuid_r(owner_id, &pw, buf, sizeof(buf), &owner) && owner)
19                         result.owner = owner->pw_name;
20                 else
21                         result.owner = format("%d", owner_id);
22         }
23         else
24                 result.owner = "None";
25
26         if(group_id!=INVALID_GID)
27         {
28                 struct group gr;
29                 struct group *group;
30                 if(!getgrgid_r(group_id, &gr, buf, sizeof(buf), &group) && group)
31                         result.group = group->gr_name;
32                 else
33                         result.group = format("%d", group_id);
34         }
35         else
36                 result.group = "None";
37 }
38
39 } // namespace FS
40 } // namespace Msp