fgetgrent(3)

πŸ’– fgetgrent(3) β€” get group file entry πŸ’–

okay bestie, pull up a chair, we're doing a libc deep dive and honestly? it's giving ✨group file✨ energy. this is the Library Functions Manual entry for fgetgrent, and by the end of this you're gonna know her like she's your mutual on the group chat. no cap. 🫢


🌸 NAME 🌸

fgetgrent β€” get group file entry

like. that's it. that's the whole job description. she reads group entries. iconic behavior tbh. πŸ‘‘


πŸ“š LIBRARY πŸ“š

Standard C library (libc, -lc)


✨ SYNOPSIS ✨

okay so here's the summoning ritual, copy it EXACTLY bestie, no typos, the compiler is not forgiving and she will ghost you if you fumble it:

#include <stdio.h>
#include <sys/types.h>
#include <grp.h>

struct group *fgetgrent(FILE *stream);

πŸŽ€ Feature Test Macro Requirements for glibc πŸŽ€

(peep feature_test_macros(7) if you wanna know more, iykyk)

fgetgrent():

  • Since glibc 2.19:
    • _DEFAULT_SOURCE
  • glibc 2.19 and earlier:
    • _SVID_SOURCE

so like, depending on how old your glibc is, you gotta define a different little magic word before your includes or she just will NOT exist. vintage glibc girlies stay winning i guess πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So fgetgrent() hands you back a pointer to a structure that's holding all the group info from the file that stream points at. πŸ’–

First time you call her? She gives you the first entry. Every call after that? She gives you the successive ones, one at a time, like she's flipping through a lil scrapbook. πŸ“–

Tiny but important: the file that stream refers to must have the same format as /etc/group β€” go check group(5) for the deets, bestie.

And the group structure? She lives in <grp.h> and she looks like THIS, character for character, do not touch her:

struct group {
    char   *gr_name;        /* group name */
    char   *gr_passwd;      /* group password */
    gid_t   gr_gid;         /* group ID */
    char  **gr_mem;         /* NULL-terminated array of pointers
                               to names of group members */
};

the gr_mem field is a NULL-terminated array of pointers to names of group members, which is a very fancy way of saying "a list that stops when it hits NULL". main character detail honestly. ✨


πŸ’€ RETURN VALUE πŸ’€

fgetgrent() returns a pointer to a group structure. slay.

But if there are no more entries, or an error happens? She returns NULL. and if it's an error situation, errno gets set to tell you what went wrong. so like, check your errno bestie, she's trying to communicate with you 😭


πŸ™ˆ ERRORS πŸ™ˆ

  • ENOMEM β€” not enough memory to allocate the group structure. she's out of room, it's a whole thing. πŸ’€

πŸ‘‘ ATTRIBUTES πŸ‘‘

for the full explanation of what these terms even mean, go read attributes(7), we're just vibing with the summary here:

  • Interface: fgetgrent()
    • Attribute: Thread safety
    • Value: MT-Unsafe race:fgetgrent
🚨 okay this one MATTERS: MT-Unsafe race:fgetgrent means she is NOT thread safe. there's a race condition situation going on. don't be out here calling her from multiple threads and expecting peace and harmony. that's the drama. 🫠

🌈 STANDARDS 🌈

None.

yeah. she's not standardized. she's just out here existing on vibes. πŸ’…


⭐ HISTORY ⭐

SVr4.

an elder. a legend. she's been around. respect her. πŸŽ€


🧚 SEE ALSO 🧚

go read these next, bestie, they're all in the group chat:


and that's the whole page, bestie!! πŸ’œ this was Linux man-pages 6.20, dated 2026-02-08, and it lives in section 3 of your friendly neighborhood fgetgrent(3) man page. mwah. go read your group files responsibly. πŸ“βœ¨

πŸ“¦ where this page comes from
  • arch rolling: man-pages 6.20-1 Β· BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
  • nixpkgs unstable: man-pages 6.20
  • πŸ“œ the page's license: Linux-man-pages-copyleft
  • πŸ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms