[uClibc-cvs] uClibc/libc/pwd_grp grent.c, 1.11, 1.12 pwent.c, 1.15, 1.16

Erik Andersen andersen at uclibc.org
Sun Nov 2 21:35:30 UTC 2003


Update of /var/cvs/uClibc/libc/pwd_grp
In directory winder:/tmp/cvs-serv23250

Modified Files:
	grent.c pwent.c 
Log Message:
Implement getgrent_r.  Rework getpwent and getgrent a bit further


Index: pwent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/pwent.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- pwent.c	1 Nov 2003 04:40:10 -0000	1.15
+++ pwent.c	2 Nov 2003 21:35:27 -0000	1.16
@@ -62,18 +62,27 @@
 	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 @@
 	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;
 }

Index: grent.c
===================================================================
RCS file: /var/cvs/uClibc/libc/pwd_grp/grent.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- grent.c	1 Nov 2003 04:40:10 -0000	1.11
+++ grent.c	2 Nov 2003 21:35:27 -0000	1.12
@@ -61,15 +61,15 @@
 	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 @@
 	}
 	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;
 }




More information about the uClibc-cvs mailing list