mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] fgetgrent
@ 2012-10-10  5:42 Isaac Dunham
  0 siblings, 0 replies; only message in thread
From: Isaac Dunham @ 2012-10-10  5:42 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 418 bytes --]

The attached patch adds support for fgetgrent; which is basically a version of getgrent that expects you to open the right file yourself.
The main use is software for administering multiple systems; I added it to compile heirloom-pkgtools, which provide that functionality.

One could redefine getgrent to call __fgetgrent, but I was more eager to get the software at the time.

-- 
Isaac Dunham <idunham@lavabit.com>

[-- Attachment #2: fgetgrent.diff --]
[-- Type: text/x-diff, Size: 958 bytes --]

diff --git a/include/grp.h b/include/grp.h
index 030d7f8..cb40e07 100644
--- a/include/grp.h
+++ b/include/grp.h
@@ -30,6 +30,10 @@ struct group  *getgrent(void);
 void           endgrent(void);
 void           setgrent(void);
 
+#ifdef _GNU_SOURCE
+struct group  *fgetgrent(FILE *stream);
+#endif
+
 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
 int getgrouplist(const char *, gid_t, gid_t *, int *);
 int setgroups(size_t, const gid_t *);
diff --git a/src/passwd/getgrent.c b/src/passwd/getgrent.c
index 429a3e5..d59bcb6 100644
--- a/src/passwd/getgrent.c
+++ b/src/passwd/getgrent.c
@@ -10,6 +10,17 @@ void setgrent()
 
 weak_alias(setgrent, endgrent);
 
+struct group *__fgetgrent(FILE *f)
+{
+	static char *line, **mem;
+	static struct group gr;
+	size_t size=0, nmem=0;
+	if (!f) return 0;
+	return __getgrent_a(f, &gr, &line, &size, &mem, &nmem);
+}
+
+weak_alias(__fgetgrent,fgetgrent);
+
 struct group *getgrent()
 {
 	static char *line, **mem;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2012-10-10  5:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-10  5:42 [PATCH] fgetgrent Isaac Dunham

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).