1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 09:24:57 +00:00

LibC: Implement getgrgid_r() and getgrnam_r()

We currently don't have those 2 functions so let's add them
This commit is contained in:
hanaa12G 2023-12-24 16:26:11 +07:00 committed by Andrew Kaster
parent 3dfd8defa9
commit 3c52c25515
4 changed files with 125 additions and 0 deletions

View file

@ -6,7 +6,9 @@
*/
#include <AK/Format.h>
#include <AK/Forward.h>
#include <AK/ScopeGuard.h>
#include <AK/StringView.h>
#include <AK/Vector.h>
#include <errno.h>
#include <errno_codes.h>
@ -53,6 +55,16 @@ struct group* getgrgid(gid_t gid)
return nullptr;
}
int getgrgid_r(gid_t gid, struct group* group_buf, char* buffer, size_t buffer_size, struct group** group_entry_ptr)
{
while (0 == getgrent_r(group_buf, buffer, buffer_size, group_entry_ptr)) {
if (group_buf->gr_gid == gid) {
return 0;
}
}
return ENOENT;
}
struct group* getgrnam(char const* name)
{
setgrent();
@ -63,6 +75,14 @@ struct group* getgrnam(char const* name)
}
return nullptr;
}
int getgrnam_r(char const* name, struct group* group_buf, char* buffer, size_t buffer_size, struct group** group_entry_ptr)
{
while (0 == getgrent_r(group_buf, buffer, buffer_size, group_entry_ptr)) {
if (!strcmp(group_buf->gr_name, name))
return 0;
}
return ENOENT;
}
static bool parse_grpdb_entry(char* buffer, size_t buffer_size, struct group& group_entry)
{