void Stat::Private::fill_owner_info(Stat::OwnerInfo &result)
{
- struct passwd *owner;
- if((owner = getpwuid(owner_id)))
- result.owner = owner->pw_name;
+ if(owner_id!=INVALID_UID)
+ {
+ struct passwd *owner;
+ if((owner = getpwuid(owner_id)))
+ result.owner = owner->pw_name;
+ else
+ result.owner = format("%d", owner_id);
+ }
else
- result.owner = format("%d", owner_id);
+ result.owner = "None";
- struct group *group;
- if((group = getgrgid(group_id)))
- result.group = group->gr_name;
+ if(group_id!=INVALID_GID)
+ {
+ struct group *group;
+ if((group = getgrgid(group_id)))
+ result.group = group->gr_name;
+ else
+ result.group = format("%d", group_id);
+ }
else
- result.group = format("%d", group_id);
+ result.group = "None";
}
} // namespace FS
struct Stat::Private
{
- UserID owner_id;
- GroupID group_id;
+ UserID owner_id = INVALID_UID;
+ GroupID group_id = INVALID_GID;
Private();
Private(const Private &);
{
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;
+ if(owner_id!=INVALID_UID)
+ {
+ 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);
+ }
else
- result.owner = format("%d", owner_id);
+ result.owner = "None";
- struct group gr;
- struct group *group;
- if(!getgrgid_r(group_id, &gr, buf, sizeof(buf), &group) && group)
- result.group = group->gr_name;
+ if(group_id!=INVALID_GID)
+ {
+ 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);
+ }
else
- result.group = format("%d", group_id);
+ result.group = "None";
}
} // namespace FS
typedef uid_t UserID;
typedef gid_t GroupID;
+const UserID INVALID_UID = -1;
+const GroupID INVALID_GID = -1;
+
} // namespace FS
} // namespace Msp
Stat::Private::~Private()
{
- if(owner_id)
+ if(owner_id!=INVALID_UID)
HeapFree(GetProcessHeap(), 0, owner_id);
- if(group_id)
+ if(group_id!=INVALID_GID)
HeapFree(GetProcessHeap(), 0, group_id);
}
void Stat::Private::fill_owner_info(Stat::OwnerInfo &result)
{
- if(owner_id)
+ if(owner_id!=INVALID_UID)
result.owner = get_account_name(owner_id);
else
result.owner = "None";
- if(group_id)
+ if(group_id!=INVALID_GID)
result.group = get_account_name(group_id);
else
result.group = "None";
typedef PSID UserID;
typedef PSID GroupID;
+const UserID INVALID_UID = 0;
+const GroupID INVALID_GID = 0;
+
} // namespace FS
} // namespace Msp