[PATCH] fix building on musl

Ben Buhse <[email protected]>
Newsgroups org.kernel.vger.autofs
Message-ID <[email protected]>
musl 1.2.5 removed basename from string.h and only kept it in libgen.h: https://git.musl-libc.org/cgit/musl/commit/?id=725e17ed6dff4d0cd22487bb64470881e86a92e7
---
 daemon/automount.c    | 20 +++++++++++++++-----
 daemon/master.c       |  1 +
 modules/lookup_file.c |  1 +
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/daemon/automount.c b/daemon/automount.c
index 474b29a..5256426 100644
--- a/daemon/automount.c
+++ b/daemon/automount.c
@@ -21,6 +21,7 @@
 
 #include <dirent.h>
 #include <getopt.h>
+#include <libgen.h>
 #include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -2538,12 +2539,21 @@ int main(int argc, char *argv[])
 
 		lookup_nss_read_master(master_list, 0);
 		if (type) {
-			const char *map = basename(name);
-			if (!map)
-				printf("%s: invalid map name %s\n",
+			const char *map = NULL;
+			char *name_dup = strdup(name);
+			if (!name_dup) {
+				printf("%s: failed to copy name %s for parsing\n",
 					program, name);
-			else
-				dump_map(master_list, type, map);
+			} else {
+				map = basename(name_dup);
+				if (!map)
+					printf("%s: invalid map name %s\n",
+						program, name);
+				else
+					dump_map(master_list, type, map);
+				free(name_dup);
+				name_dup = NULL;
+			}
 		} else
 			master_show_mounts(master_list);
 
diff --git a/daemon/master.c b/daemon/master.c
index f2c11e9..1455e40 100644
--- a/daemon/master.c
+++ b/daemon/master.c
@@ -21,6 +21,7 @@
 #include <string.h>
 #include <memory.h>
 #include <limits.h>
+#include <libgen.h>
 #include <signal.h>
 #include <sys/types.h>
 #include <sys/stat.h>
diff --git a/modules/lookup_file.c b/modules/lookup_file.c
index 99f2e21..4914395 100644
--- a/modules/lookup_file.c
+++ b/modules/lookup_file.c
@@ -15,6 +15,7 @@
 
 #include <stdio.h>
 #include <malloc.h>
+#include <libgen.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
-- 
2.45.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.