Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3702)

Unified Diff: fusl/src/passwd/getpwent_a.c

Issue 1573973002: Add a "fork" of musl as //fusl. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « fusl/src/passwd/getpwent.c ('k') | fusl/src/passwd/getspent.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/passwd/getpwent_a.c
diff --git a/fusl/src/passwd/getpwent_a.c b/fusl/src/passwd/getpwent_a.c
new file mode 100644
index 0000000000000000000000000000000000000000..d1b4b53ce2008234ea37a4e5cfe5e78f5456142f
--- /dev/null
+++ b/fusl/src/passwd/getpwent_a.c
@@ -0,0 +1,54 @@
+#include "pwf.h"
+#include <pthread.h>
+
+static unsigned atou(char **s)
+{
+ unsigned x;
+ for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0');
+ return x;
+}
+
+int __getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size, struct passwd **res)
+{
+ ssize_t l;
+ char *s;
+ int rv = 0;
+ int cs;
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
+ for (;;) {
+ if ((l=getline(line, size, f)) < 0) {
+ rv = ferror(f) ? errno : 0;
+ free(*line);
+ *line = 0;
+ pw = 0;
+ break;
+ }
+ line[0][l-1] = 0;
+
+ s = line[0];
+ pw->pw_name = s++;
+ if (!(s = strchr(s, ':'))) continue;
+
+ *s++ = 0; pw->pw_passwd = s;
+ if (!(s = strchr(s, ':'))) continue;
+
+ *s++ = 0; pw->pw_uid = atou(&s);
+ if (*s != ':') continue;
+
+ *s++ = 0; pw->pw_gid = atou(&s);
+ if (*s != ':') continue;
+
+ *s++ = 0; pw->pw_gecos = s;
+ if (!(s = strchr(s, ':'))) continue;
+
+ *s++ = 0; pw->pw_dir = s;
+ if (!(s = strchr(s, ':'))) continue;
+
+ *s++ = 0; pw->pw_shell = s;
+ break;
+ }
+ pthread_setcancelstate(cs, 0);
+ *res = pw;
+ if (rv) errno = rv;
+ return rv;
+}
« no previous file with comments | « fusl/src/passwd/getpwent.c ('k') | fusl/src/passwd/getspent.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698