diff options
author | Eric Andersen <andersen@codepoet.org> | 2003-11-02 21:35:27 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2003-11-02 21:35:27 +0000 |
commit | ded0e9aba41f65618cc4b329cdad753f01f9875a (patch) | |
tree | c485b0335483cc0aadf5313dec507fe73391609f /libc/pwd_grp/pwent.c | |
parent | 44ecacea6b45d7ae5d5eb70fe01d7ade4b90c525 (diff) |
Implement getgrent_r. Rework getpwent and getgrent a bit further
Diffstat (limited to 'libc/pwd_grp/pwent.c')
-rw-r--r-- | libc/pwd_grp/pwent.c | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/libc/pwd_grp/pwent.c b/libc/pwd_grp/pwent.c index e983a73a0..557bffd65 100644 --- a/libc/pwd_grp/pwent.c +++ b/libc/pwd_grp/pwent.c @@ -62,18 +62,27 @@ void endpwent(void) LOCK; if (pw_fd > -1) close(pw_fd); - pw_fd = -1; + pw_fd = -9; UNLOCK; } int getpwent_r (struct passwd *password, char *buff, - size_t buflen, struct passwd **result) + size_t buflen, struct passwd **result) { int ret=EINVAL; - LOCK; *result = NULL; - if ((ret=__getpwent_r(password, buff, buflen, pw_fd)) == 0) { + LOCK; + /* Open /etc/passwd if not yet opened */ + if (pw_fd == -9) { + setpwent(); + } + if (pw_fd == -1) { + UNLOCK; + return -1; + } + ret=__getpwent_r(password, buff, buflen, pw_fd); + if (ret == 0) { UNLOCK; *result = password; return 0; @@ -90,21 +99,10 @@ struct passwd *getpwent(void) static struct passwd pwd; static char line_buff[PWD_BUFFER_SIZE]; - LOCK; - /* Open /etc/passwd if not yet opened */ - if (pw_fd == -9) { - setpwent(); - } - if (pw_fd == -1) { - UNLOCK; - return NULL; - } - ret=getpwent_r(&pwd, line_buff, sizeof(line_buff), &result); + ret = getpwent_r(&pwd, line_buff, sizeof(line_buff), &result); if (ret == 0) { - UNLOCK; return &pwd; } - UNLOCK; __set_errno(ret); return NULL; } |