From 87c5c711f6f828053abd754628a0067696cfd54d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>
Date: Mon, 9 Dec 2019 09:36:12 +0100
Subject: [PATCH] musl: add missing fgetspent_r

From: =?UTF-8?q?Andreas=20M=C3=BCller?= <schnitzeltony@gmail.com>

Stolen from void-linux

Upstream-Status: Inappropriate [musl-specific]
---
 src/daemon.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/src/daemon.c b/src/daemon.c
index aa9d050..cc53eae 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -215,6 +215,28 @@ remove_cache_files (const gchar *user_name)
         g_remove (icon_filename);
 }
 
+#ifndef __GLIBC__
+ /* Musl libc does not support fgetspent_r(), write own
+  * wrapper
+  */
+static int fgetspent_r(FILE *fp, struct spwd *spbuf, char *buf, size_t buflen, struct spwd **spbufp) {
+       struct spwd *shadow_entry = fgetspent(fp);
+       if(!shadow_entry)
+               return -1;
+       size_t namplen = strlen(shadow_entry->sp_namp);
+       size_t pwdplen = strlen(shadow_entry->sp_pwdp);
+
+       if(namplen + pwdplen + 2 > buflen)
+               return -1;
+
+       *spbufp = memcpy(spbuf, shadow_entry, sizeof(struct spwd));
+       spbuf->sp_namp = strncpy(buf, shadow_entry->sp_namp, namplen + 1);
+       spbuf->sp_pwdp = strncpy(buf + namplen + 1, shadow_entry->sp_pwdp, pwdplen + 1);
+
+       return 0;
+}
+#endif
+
 static struct passwd *
 entry_generator_fgetpwent (Daemon       *daemon,
                            GHashTable   *users,
