+/* Look up a user/group and convert it to string form (either strictly numeric
+ * or numeric plus symbolic). Caches the results of the call to
+ * getpwuid/getgrgid. */
+string user_to_string(uid_t uid) {
+ static map<uid_t, string> user_cache;
+ map<uid_t, string>::const_iterator i = user_cache.find(uid);
+ if (i != user_cache.end())
+ return i->second;
+
+ string result = encode_int(uid);
+ struct passwd *pwd = getpwuid(uid);
+ if (pwd != NULL && pwd->pw_name != NULL) {
+ result += " (" + uri_encode(pwd->pw_name) + ")";
+ }
+ user_cache[uid] = result;
+ return result;
+}
+
+string group_to_string(gid_t gid) {
+ static map<gid_t, string> group_cache;
+ map<gid_t, string>::const_iterator i = group_cache.find(gid);
+ if (i != group_cache.end())
+ return i->second;
+
+ string result = encode_int(gid);
+ struct group *grp = getgrgid(gid);
+ if (grp != NULL && grp->gr_name != NULL) {
+ result += " (" + uri_encode(grp->gr_name) + ")";
+ }
+ group_cache[gid] = result;
+ return result;
+}
+