fgetpwent(3)

πŸ’– fgetpwent(3) β€” the manual page, but make it bestie-coded πŸ’–

okay so bestie, we're in section 3 of the library functions manual today and the star of the show is fgetpwent β€” she reads password file entries off a stream you already opened. no cap, she's a whole vibe.


πŸŽ€ LIBRARY πŸŽ€

Standard C library (libc, -lc). the classic. the blueprint. πŸ’…


✨ SYNOPSIS ✨

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

struct passwd *fgetpwent(FILE *stream);

🧚 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):

fgetpwent():
    Since glibc 2.19:
        _DEFAULT_SOURCE
    glibc 2.19 and earlier:
        _SVID_SOURCE

like, define the right macro or she literally will not show up. that's the rules.


🌸 DESCRIPTION 🌸

so fgetpwent() hands you back a pointer to a structure holding the broken out fields of one line in the file stream. first call? she gives you the first entry. after that? successive entries, one at a time, like she's scrolling the feed for you. 🫢

the file that stream points at has to have the same format as /etc/passwd (peep passwd(5) for the tea on that format).

the passwd structure lives in <pwd.h> and looks exactly like this:

struct passwd {
    char   *pw_name;       /* username */
    char   *pw_passwd;     /* user password */
    uid_t   pw_uid;        /* user ID */
    gid_t   pw_gid;        /* group ID */
    char   *pw_gecos;      /* real name */
    char   *pw_dir;        /* home directory */
    char   *pw_shell;      /* shell program */
};

seven fields, all iconic, no notes. πŸ‘‘


πŸ’€ RETURN VALUE πŸ’€

fgetpwent() gives you back a pointer to a passwd structure β€” or NULL if there are no more entries or an error happened. and if an error happened? errno gets set to tell you what went down. not me getting a NULL and having to check errno like a detective. 😭


πŸ™ˆ ERRORS πŸ™ˆ

  • ENOMEM β€” not enough memory to allocate the passwd structure.

that's the whole list. one error. she keeps it simple. periodt.


πŸ“ FILES πŸ“

  • /etc/passwd β€” password database file

🌈 ATTRIBUTES 🌈

for the explanation of the terms used in this here section, go see attributes(7).

  • Interface: fgetpwent()
  • Attribute: Thread safety
  • Value: MT-Unsafe race:fgetpwent
⚠️ bestie. she is MT-Unsafe and there's a race on fgetpwent. translate that: don't be sharing her across threads unsupervised. multitasking is not her moment. πŸ’€

πŸ‘‘ STANDARDS πŸ‘‘

None. literally none. she's not in any standard, she's just out here existing. πŸ’…


πŸ¦‹ HISTORY πŸ¦‹

SVr4.

an elder. a legend. she's been around.


⭐ SEE ALSO ⭐

endpwent(3), fgetpwent_r(3), fopen(3), getpw(3), getpwent(3), getpwnam(3), getpwuid(3), putpwent(3), setpwent(3), passwd(5)


and that's the whole page, bestie β€” you ate that πŸ’– this one's from Linux man-pages 6.20, dated 2026-02-08, and it's the fgetpwent(3) page. go forth and read your passwd entries responsibly. mwah πŸŽ€βœ¨

πŸ“¦ 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