aboutsummaryrefslogtreecommitdiff
path: root/coreutils/test.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2024-10-07 01:20:43 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2024-10-07 01:20:43 +0200
commit748b1681549067f2e27ab2b9102ef9352cfa8a4c (patch)
tree1b0bc13cd7a5297747ef600999a63dc0a97e8d06 /coreutils/test.c
parentbb5525613ec109aa30d2cb1db84e18aa0b084576 (diff)
downloadbusybox-w32-748b1681549067f2e27ab2b9102ef9352cfa8a4c.tar.gz
busybox-w32-748b1681549067f2e27ab2b9102ef9352cfa8a4c.tar.bz2
busybox-w32-748b1681549067f2e27ab2b9102ef9352cfa8a4c.zip
libbb: move is_in_supplementary_groups() from test to libbb
function old new delta is_in_supplementary_groups - 54 +54 nexpr 766 721 -45 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/1 up/down: 54/-45) Total: 9 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'coreutils/test.c')
-rw-r--r--coreutils/test.c20
1 files changed, 1 insertions, 19 deletions
diff --git a/coreutils/test.c b/coreutils/test.c
index c02c92745..874285704 100644
--- a/coreutils/test.c
+++ b/coreutils/test.c
@@ -637,32 +637,14 @@ static int binop(void)
637 /*return 1; - NOTREACHED */ 637 /*return 1; - NOTREACHED */
638} 638}
639 639
640static void initialize_group_array(void)
641{
642 group_array = bb_getgroups(&ngroups, NULL);
643}
644
645/* Return non-zero if GID is one that we have in our groups list. */ 640/* Return non-zero if GID is one that we have in our groups list. */
646//XXX: FIXME: duplicate of existing libbb function?
647// see toplevel TODO file:
648// possible code duplication ingroup() and is_a_group_member()
649static int is_a_group_member(gid_t gid) 641static int is_a_group_member(gid_t gid)
650{ 642{
651 int i;
652
653 /* Short-circuit if possible, maybe saving a call to getgroups(). */ 643 /* Short-circuit if possible, maybe saving a call to getgroups(). */
654 if (gid == getgid() || gid == getegid()) 644 if (gid == getgid() || gid == getegid())
655 return 1; 645 return 1;
656 646
657 if (ngroups == 0) 647 return is_in_supplementary_groups(&ngroups, &group_array, gid);
658 initialize_group_array();
659
660 /* Search through the list looking for GID. */
661 for (i = 0; i < ngroups; i++)
662 if (gid == group_array[i])
663 return 1;
664
665 return 0;
666} 648}
667 649
668/* 650/*