summaryrefslogtreecommitdiff
path: root/libc/pwd_grp/grent.c
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-11-02 21:35:27 +0000
committerEric Andersen <andersen@codepoet.org>2003-11-02 21:35:27 +0000
commitded0e9aba41f65618cc4b329cdad753f01f9875a (patch)
treec485b0335483cc0aadf5313dec507fe73391609f /libc/pwd_grp/grent.c
parent44ecacea6b45d7ae5d5eb70fe01d7ade4b90c525 (diff)
Implement getgrent_r. Rework getpwent and getgrent a bit further
Diffstat (limited to 'libc/pwd_grp/grent.c')
-rw-r--r--libc/pwd_grp/grent.c32
1 files changed, 24 insertions, 8 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;
}