diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lib.c | 23 | ||||
-rw-r--r-- | lib/lib.h | 2 |
2 files changed, 25 insertions, 0 deletions
@@ -1184,3 +1184,26 @@ int regexec0(regex_t *preg, char *string, long len, int nmatch, len -= ll; } } + +// Return user name or string representation of number, returned buffer +// lasts until next call. +char *getusername(uid_t uid) +{ + struct passwd *pw = bufgetpwuid(uid); + static char unum[12]; + + sprintf(unum, "%u", (unsigned)uid); + return pw ? pw->pw_name : unum; +} + +// Return group name or string representation of number, returned buffer +// lasts until next call. +char *getgroupname(gid_t gid) +{ + struct group *gr = bufgetgrgid(gid); + static char gnum[12]; + + sprintf(gnum, "%u", (unsigned)gid); + return gr ? gr->gr_name : gnum; +} + @@ -223,6 +223,8 @@ int readlinkat0(int dirfd, char *path, char *buf, int len); int readlink0(char *path, char *buf, int len); int regexec0(regex_t *preg, char *string, long len, int nmatch, regmatch_t pmatch[], int eflags); +char *getusername(uid_t uid); +char *getgroupname(gid_t gid); #define HR_SPACE 1 // Space between number and units #define HR_B 2 // Use "B" for single byte units |