Skip to content

libc/unistd: add getgroups()#19182

Open
xiaoxiang781216 wants to merge 1 commit into
apache:masterfrom
xiaoxiang781216:upstream-getgroups
Open

libc/unistd: add getgroups()#19182
xiaoxiang781216 wants to merge 1 commit into
apache:masterfrom
xiaoxiang781216:upstream-getgroups

Conversation

@xiaoxiang781216

Copy link
Copy Markdown
Contributor

Summary

Add getgroups() to the C library. POSIX requires getgroups() to
return the supplementary group IDs of the calling process. NuttX has no
notion of supplementary group IDs, so the calling process is treated as
belonging to a single group: its effective group ID.

Behavior:

  • gidsetsize == 0: return the number of group IDs (1) without writing to
    grouplist, per POSIX.
  • gidsetsize < 0: fail with EINVAL.
  • otherwise: store the effective group ID (getegid()) in grouplist[0]
    and return 1.

It is declared in <unistd.h> and always built, since it only depends on
the public getegid().

Impact

New public POSIX API. No change to existing behavior or build for code
that does not call getgroups(). Helps porting third-party software that
expects getgroups() to be available.

Testing

Built the sim:nsh configuration on Linux (x86_64, GCC) with
CONFIG_LIBC_GROUP_FILE both enabled and disabled. checkpatch.sh passes
on the changed files.

@github-actions github-actions Bot added Area: OS Components OS Components issues Size: S The size of the change in this PR is small labels Jun 20, 2026
@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown

MemBrowse Memory Report

No memory changes detected for:

@xiaoxiang781216 xiaoxiang781216 force-pushed the upstream-getgroups branch 2 times, most recently from 1d59240 to d4db122 Compare June 20, 2026 18:15
Add getgroups() to the C library.  NuttX has no supplementary group
IDs, so it reports a single group, the effective group ID, and follows
POSIX for the gidsetsize == 0 and short-buffer (EINVAL) cases.

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant