diff --git a/Userland/Libraries/LibCore/System.cpp b/Userland/Libraries/LibCore/System.cpp index 92ab111dcd..37cca47260 100644 --- a/Userland/Libraries/LibCore/System.cpp +++ b/Userland/Libraries/LibCore/System.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Andreas Kling + * Copyright (c) 2021-2022, Andreas Kling * Copyright (c) 2021, Kenneth Myhra * Copyright (c) 2021, Sam Atkins * @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -742,4 +743,18 @@ ErrorOr> pipe2([[maybe_unused]] int flags) return fds; } +ErrorOr> getgroups() +{ + int count = ::getgroups(0, nullptr); + if (count < 0) + return Error::from_syscall("getgroups"sv, -errno); + if (count == 0) + return Vector {}; + Vector groups; + TRY(groups.try_resize(count)); + if (::getgroups(count, groups.data()) < 0) + return Error::from_syscall("getgroups"sv, -errno); + return groups; +} + } diff --git a/Userland/Libraries/LibCore/System.h b/Userland/Libraries/LibCore/System.h index d30457b495..1353108885 100644 --- a/Userland/Libraries/LibCore/System.h +++ b/Userland/Libraries/LibCore/System.h @@ -105,5 +105,5 @@ ErrorOr setsockopt(int sockfd, int level, int option, void const* value, s ErrorOr getsockname(int sockfd, struct sockaddr*, socklen_t*); ErrorOr getpeername(int sockfd, struct sockaddr*, socklen_t*); ErrorOr socketpair(int domain, int type, int protocol, int sv[2]); - +ErrorOr> getgroups(); }