getpwent_r(3) Library Functions Manual getpwent_r(3) getpwent_r, fgetpwent_r - ( ) Standard C library (libc, -lc) #include int getpwent_r(struct passwd *restrict pwbuf, char buf[restrict .size], size_t size, struct passwd **restrict pwbufp); int fgetpwent_r(FILE *restrict stream, struct passwd *restrict pwbuf, char buf[restrict .size], size_t size, struct passwd **restrict pwbufp); glibc (. feature_test_macros(7)): getpwent_r(), glibc 2.19: _DEFAULT_SOURCE glibc 2.19 : _BSD_SOURCE || _SVID_SOURCE fgetpwent_r(): glibc 2.19: _DEFAULT_SOURCE glibc 2.19 : _SVID_SOURCE getpwent_r() fgetpwent_r() getpwent(3) fgetpwent(3). , setpwent(3). stream. passwd : struct passwd { char *pw_name; /* */ char *pw_passwd; /* */ uid_t pw_uid; /* */ gid_t pw_gid; /* */ char *pw_gecos; /* */ char *pw_dir; /* */ char *pw_shell; /* */ }; passwd(5). The nonreentrant functions return a pointer to static storage, where this static storage contains further pointers to user name, password, gecos field, home directory and shell. The reentrant functions described here return all of that in caller-provided buffers. First of all there is the buffer pwbuf that can hold a struct passwd. And next the buffer buf of size size that can hold additional strings. The result of these functions, the struct passwd read from the stream, is stored in the provided buffer *pwbuf, and a pointer to this struct passwd is returned in *pwbufp. 0 *pwbufp struct passwd. *pwbufp NULL. ENOENT . ERANGE . . attributes(7). +----------------------------+----------------------------------------------------------+--------------------------+ | | | | +----------------------------+----------------------------------------------------------+--------------------------+ |getpwent_r() | | MT-Unsafe race:pwent | | | | locale | +----------------------------+----------------------------------------------------------+--------------------------+ |fgetpwent_r() | | MT-Safe | +----------------------------+----------------------------------------------------------+--------------------------+ pwent race:pwent , setpwent(), getpwent(), endpwent() getpwent_r(), . Other systems use the prototype struct passwd * getpwent_r(struct passwd *pwd, char buf[.size], int size); , , int getpwent_r(struct passwd *pwd, char buf[.size], int size, FILE **pw_fp); . , POSIX getpwnam_r(3). getpwent_r() , . #define _GNU_SOURCE #include #include #include #include #define BUFLEN 4096 int main(void) { struct passwd pw; struct passwd *pwp; char buf[BUFLEN]; int i; setpwent(); while (1) { i = getpwent_r(&pw, buf, sizeof(buf), &pwp); if (i) break; printf("%s (%jd)\tHOME %s\tSHELL %s\n", pwp->pw_name, (intmax_t) pwp->pw_uid, pwp->pw_dir, pwp->pw_shell); } endpwent(); exit(EXIT_SUCCESS); } fgetpwent(3), getpw(3), getpwent(3), getpwnam(3), getpwuid(3), putpwent(3), passwd(5) () Azamat Hackimov , Dmitry Bolkhovskikh , Vladislav , Yuri Kozlov , Kirill Rekhov ; GNU (GNU General Public License - GPL, 3 ) , - . - , , () () () <>. Linux man-pages 6.12 24 2024 . getpwent_r(3)