summaryrefslogtreecommitdiff
path: root/libc/pwd_grp
diff options
context:
space:
mode:
Diffstat (limited to 'libc/pwd_grp')
-rw-r--r--libc/pwd_grp/grent.c32
-rw-r--r--libc/pwd_grp/pwent.c30
2 files changed, 38 insertions, 24 deletions
diff --git a/libc/pwd_grp/grent.c b/libc/pwd_grp/grent.c
index e05459c2d..b2d6f8c6a 100644
--- a/libc/pwd_grp/grent.c
+++ b/libc/pwd_grp/grent.c
@@ -61,15 +61,15 @@ void endgrent(void)
LOCK;
if (grp_fd > -1)
close(grp_fd);
- grp_fd = -1;
+ grp_fd = -9;
UNLOCK;
}
-struct group *getgrent(void)
+int getgrent_r (struct group *grp, char *buff,
+ size_t buflen, struct group **result)
{
- int ret;
- static struct group grp;
- static char line_buff[PWD_BUFFER_SIZE];
+ int ret=EINVAL;
+ *result = NULL;
LOCK;
/* Open /etc/group if it has never been opened */
@@ -78,14 +78,30 @@ struct group *getgrent(void)
}
if (grp_fd == -1) {
UNLOCK;
- return NULL;
+ return -1;
}
- ret = __getgrent_r(&grp, line_buff, sizeof(line_buff), grp_fd);
+ ret=__getgrent_r(grp, buff, buflen, grp_fd);
if (ret == 0) {
UNLOCK;
- return &grp;
+ *result = grp;
+ return 0;
}
UNLOCK;
__set_errno(ret);
+ return ret;
+}
+
+struct group *getgrent(void)
+{
+ int ret;
+ struct group *result;
+ static struct group grp;
+ static char line_buff[PWD_BUFFER_SIZE];
+
+ ret = getgrent_r(&grp, line_buff, sizeof(line_buff), &result);
+ if (ret == 0) {
+ return &grp;
+ }
+ __set_errno(ret);
return NULL;
}
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;
}