]> git.tdb.fi Git - libs/core.git/blobdiff - source/fs/unix/stat_owner.cpp
Minimalistic port for Android
[libs/core.git] / source / fs / unix / stat_owner.cpp
diff --git a/source/fs/unix/stat_owner.cpp b/source/fs/unix/stat_owner.cpp
new file mode 100644 (file)
index 0000000..1a33d74
--- /dev/null
@@ -0,0 +1,30 @@
+#include <grp.h>
+#include <pwd.h>
+#include <msp/strings/format.h>
+#include "stat.h"
+#include "stat_private.h"
+
+namespace Msp {
+namespace FS {
+
+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);
+}
+
+} // namespace FS
+} // namespace Msp