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

Stolen from void-linux

Upstream-Status: Inappropriate [musl-specific]

---
 src/daemon.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/daemon.c b/src/daemon.c
index c52bda3..a7676fe 100644
--- a/src/daemon.c
+++ b/src/daemon.c
@@ -164,6 +164,26 @@ remove_cache_files (const gchar *user_name)
         g_remove (icon_filename);
 }
 
+/* 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;
+}
+
 static struct passwd *
 entry_generator_fgetpwent (Daemon       *daemon,
                            GHashTable   *users,
