aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRob Landley <rob@landley.net>2016-05-20 14:28:13 -0500
committerRob Landley <rob@landley.net>2016-05-20 14:28:13 -0500
commitb602f1c1513328fe91f70233c78d11d9e638982d (patch)
treedd0b209caa1d5027f56bccf2b8364cabbfa20570 /lib
parent9cfdb48722cba8bfaafee9de61411618d66365f3 (diff)
downloadtoybox-b602f1c1513328fe91f70233c78d11d9e638982d.tar.gz
Add bufgetgrgid()
Diffstat (limited to 'lib')
-rw-r--r--lib/lib.c28
-rw-r--r--lib/lib.h1
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/lib.c b/lib/lib.c
index 98597b24..66814a45 100644
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -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;
+}
diff --git a/lib/lib.h b/lib/lib.h
index b1f4ca11..f545a794 100644
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -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