about summary refs log tree commit diff
path: root/src/passwd/putgrent.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/passwd/putgrent.c')
-rw-r--r--src/passwd/putgrent.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/passwd/putgrent.c b/src/passwd/putgrent.c
new file mode 100644
index 00000000..d7847b15
--- /dev/null
+++ b/src/passwd/putgrent.c
@@ -0,0 +1,14 @@
+#include <grp.h>
+#include <stdio.h>
+
+int putgrent(const struct group *gr, FILE *f)
+{
+	int r;
+	size_t i;
+	flockfile(f);
+	r = fprintf(f, "%s:%s:%d:", gr->gr_name, gr->gr_passwd, gr->gr_gid);
+	if (gr->gr_mem) for (i=0; gr->gr_mem[i]; i++)
+		if (fprintf(f, "%s%s", i?",":"", gr->gr_mem[i])<0) r = -1;
+	funlockfile(f);
+	return r<0 ? -1 : 0;
+}