summaryrefslogtreecommitdiff
path: root/file.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-10-11 23:35:26 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-10-14 00:20:13 +0900
commit8f480eafabebc55249f1436ab0ca059c239a8134 (patch)
tree744026186d7c3e8510a1a5e9047761603312928e /file.c
parent9a3333986f76522fd6e0b9ca92045895a1aa45e0 (diff)
rb_group_member: Simplify
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/4963
Diffstat (limited to 'file.c')
-rw-r--r--file.c24
1 files changed, 4 insertions, 20 deletions
diff --git a/file.c b/file.c
index d60a46c350e..23f81406c65 100644
--- a/file.c
+++ b/file.c
@@ -1451,7 +1451,7 @@ rb_group_member(GETGROUPS_T gid)
return FALSE;
#else
int rv = FALSE;
- int groups = 16;
+ int groups;
VALUE v = 0;
GETGROUPS_T *gary;
int anum = -1;
@@ -1459,25 +1459,9 @@ rb_group_member(GETGROUPS_T gid)
if (getgid() == gid || getegid() == gid)
return TRUE;
- /*
- * On Mac OS X (Mountain Lion), NGROUPS is 16. But libc and kernel
- * accept more larger value.
- * So we don't trunk NGROUPS anymore.
- */
- while (groups <= RB_MAX_GROUPS) {
- gary = ALLOCV_N(GETGROUPS_T, v, groups);
- anum = getgroups(groups, gary);
- if (anum != -1 && anum != groups)
- break;
- groups *= 2;
- if (v) {
- ALLOCV_END(v);
- v = 0;
- }
- }
- if (anum == -1)
- return FALSE;
-
+ groups = getgroups(0, NULL);
+ gary = ALLOCV_N(GETGROUPS_T, v, groups);
+ anum = getgroups(groups, gary);
while (--anum >= 0) {
if (gary[anum] == gid) {
rv = TRUE;