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

Unified Diff: fusl/src/passwd/getpw_r.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/getpw_a.c ('k') | fusl/src/passwd/getpwent.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: fusl/src/passwd/getpw_r.c
diff --git a/fusl/src/passwd/getpw_r.c b/fusl/src/passwd/getpw_r.c
new file mode 100644
index 0000000000000000000000000000000000000000..e8cc811e4d898f91c26d05b16b4456fda9d6601b
--- /dev/null
+++ b/fusl/src/passwd/getpw_r.c
@@ -0,0 +1,41 @@
+#include "pwf.h"
+#include <pthread.h>
+
+#define FIX(x) (pw->pw_##x = pw->pw_##x-line+buf)
+
+static int getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf, size_t size, struct passwd **res)
+{
+ char *line = 0;
+ size_t len = 0;
+ int rv = 0;
+ int cs;
+
+ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
+
+ rv = __getpw_a(name, uid, pw, &line, &len, res);
+ if (*res && size < len) {
+ *res = 0;
+ rv = ERANGE;
+ }
+ if (*res) {
+ memcpy(buf, line, len);
+ FIX(name);
+ FIX(passwd);
+ FIX(gecos);
+ FIX(dir);
+ FIX(shell);
+ }
+ free(line);
+ pthread_setcancelstate(cs, 0);
+ return rv;
+}
+
+int getpwnam_r(const char *name, struct passwd *pw, char *buf, size_t size, struct passwd **res)
+{
+ return getpw_r(name, 0, pw, buf, size, res);
+}
+
+int getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t size, struct passwd **res)
+{
+ return getpw_r(0, uid, pw, buf, size, res);
+}
« no previous file with comments | « fusl/src/passwd/getpw_a.c ('k') | fusl/src/passwd/getpwent.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698