summaryrefslogtreecommitdiff
path: root/src/passwd/getgrent_a.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2011-02-12 00:22:29 -0500
committerRich Felker <dalias@aerifal.cx>2011-02-12 00:22:29 -0500
commit0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 (patch)
tree6eaef0d8a720fa3da580de87b647fff796fe80b3 /src/passwd/getgrent_a.c
downloadmusl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.tar.gz
musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.tar.bz2
musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.tar.xz
musl-0b44a0315b47dd8eced9f3b7f31580cf14bbfc01.zip
initial check-in, version 0.5.0v0.5.0
Diffstat (limited to 'src/passwd/getgrent_a.c')
-rw-r--r--src/passwd/getgrent_a.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/passwd/getgrent_a.c b/src/passwd/getgrent_a.c
new file mode 100644
index 00000000..ccb51d52
--- /dev/null
+++ b/src/passwd/getgrent_a.c
@@ -0,0 +1,46 @@
+#include "pwf.h"
+
+struct group *__getgrent_a(FILE *f, struct group *gr, char **line, size_t *size, char ***mem, size_t *nmem)
+{
+ ssize_t l;
+ char *s, *mems;
+ size_t i;
+
+ for (;;) {
+ if ((l=getline(line, size, f)) < 0) {
+ free(*line);
+ *line = 0;
+ return 0;
+ }
+ line[0][l-1] = 0;
+
+ s = line[0];
+ gr->gr_name = s++;
+ if (!(s = strchr(s, ':'))) continue;
+
+ *s++ = 0; gr->gr_passwd = s;
+ if (!(s = strchr(s, ':'))) continue;
+
+ *s++ = 0; gr->gr_gid = atoi(s);
+ if (!(s = strchr(s, ':'))) continue;
+
+ *s++ = 0; mems = s;
+ break;
+ }
+
+ for (*nmem=!!*s; *s; s++)
+ if (*s==',') ++*nmem;
+ free(*mem);
+ *mem = calloc(sizeof(char *), *nmem+1);
+ if (!*mem) {
+ free(*line);
+ *line = 0;
+ return 0;
+ }
+ mem[0][0] = mems;
+ for (s=mems, i=0; *s; s++)
+ if (*s==',') *s++ = 0, mem[0][++i] = s;
+ mem[0][++i] = 0;
+ gr->gr_mem = *mem;
+ return gr;
+}