summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2017-07-28 06:09:24 +0000
committerWilliam Pitcock <nenolod@dereferenced.org>2017-07-28 06:09:24 +0000
commitf4d9c794491808dfba3d0ec83d6907a6e9adbd84 (patch)
tree4e1178a759364737426b6a9bca3bc3205ae90223
parentaadf39c06a5573439f9a733d05946e723e77992b (diff)
downloadgcompat-f4d9c794491808dfba3d0ec83d6907a6e9adbd84.tar.gz
gcompat-f4d9c794491808dfba3d0ec83d6907a6e9adbd84.tar.bz2
gcompat-f4d9c794491808dfba3d0ec83d6907a6e9adbd84.tar.xz
gcompat-f4d9c794491808dfba3d0ec83d6907a6e9adbd84.zip
libgcompat: add getpwent_r() and fgetpwent_r() stubs
-rw-r--r--Makefile1
-rw-r--r--libgcompat/pwd.c55
2 files changed, 56 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index e71ad20..59b365d 100644
--- a/Makefile
+++ b/Makefile
@@ -6,6 +6,7 @@ LIBGCOMPAT_SRC = \
libgcompat/malloc.c \
libgcompat/math.c \
libgcompat/pthread.c \
+ libgcompat/pwd.c \
libgcompat/resource.c \
libgcompat/setjmp.c \
libgcompat/stdio.c \
diff --git a/libgcompat/pwd.c b/libgcompat/pwd.c
new file mode 100644
index 0000000..2e09aea
--- /dev/null
+++ b/libgcompat/pwd.c
@@ -0,0 +1,55 @@
+/* some musl versions incorrectly mark fgetpwent() as a GNU extension */
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include <errno.h>
+#include <pwd.h>
+#include <string.h>
+
+
+int getpwent_r(struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) {
+ struct passwd *pwd;
+
+ if (pwbufp == NULL || pwbuf == NULL)
+ return ERANGE;
+
+ if (buflen < 1)
+ return ERANGE;
+
+ if (buf != NULL)
+ *buf = '\0';
+
+ if ((pwd = getpwent()) == NULL) {
+ *pwbufp = NULL;
+ return ENOENT;
+ }
+
+ memcpy(pwbuf, pwd, sizeof(*pwd));
+ *pwbufp = pwbuf;
+
+ return 0;
+}
+
+
+int fgetpwent_r(FILE *filp, struct passwd *pwbuf, char *buf, size_t buflen, struct passwd **pwbufp) {
+ struct passwd *pwd;
+
+ if (pwbufp == NULL || pwbuf == NULL)
+ return ERANGE;
+
+ if (buflen < 1)
+ return ERANGE;
+
+ if (buf != NULL)
+ *buf = '\0';
+
+ if ((pwd = fgetpwent(filp)) == NULL) {
+ *pwbufp = NULL;
+ return ENOENT;
+ }
+
+ memcpy(pwbuf, pwd, sizeof(*pwd));
+ *pwbufp = pwbuf;
+
+ return 0;
+}