diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/lib.c | 28 | ||||
-rw-r--r-- | lib/lib.h | 1 |
2 files changed, 29 insertions, 0 deletions
@@ -1102,3 +1102,31 @@ struct passwd *bufgetpwuid(uid_t uid) return &list->pw; } + +// Return cached passwd entries. +struct group *bufgetgrgid(gid_t gid) +{ + struct grgidbuf_list { + struct grgidbuf_list *next; + struct group gr; + } *list; + struct group *temp; + static struct grgidbuf_list *grgidbuf; + + for (list = grgidbuf; list; list = list->next) + if (list->gr.gr_gid == gid) return &(list->gr); + + list = xmalloc(512); + list->next = grgidbuf; + + errno = getgrgid_r(gid, &list->gr, sizeof(*list)+(char *)list, + 512-sizeof(*list), &temp); + if (!temp) { + free(list); + + return 0; + } + grgidbuf = list; + + return &list->gr; +} @@ -206,6 +206,7 @@ int dev_minor(int dev); int dev_major(int dev); int dev_makedev(int major, int minor); struct passwd *bufgetpwuid(uid_t uid); +struct group *bufgetgrgid(gid_t gid); #define HR_SPACE 1 // Space between number and units #define HR_B 2 // Use "B" for single byte units |