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 thepasswdstructure.
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
- Copyright 1993, David Metcalfe <david@prism.demon.co.uk>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms