diff mbox series

fix build on systems without memrchr(3)

Message ID 4ac525c0-f48e-4e27-87e2-9f1f8eb84434@inlv.org (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show
Series fix build on systems without memrchr(3) | expand

Commit Message

Martijn Dekker June 22, 2024, 2:25 p.m. UTC
memrchr(3) is non-standard, and has been ported from glibc to FreeBSD, NetSBD 
and OpenBSD, but not to macOS, at least as of 12.7.5. So we need a test for 
it. As far as I can tell, *name is a zero-terminated C string, so it should 
work to use strrchr(3) as a fallback. Patch attached (to avoid whitespace errors).
diff mbox series

Patch

diff --git a/configure.ac b/configure.ac
index 338d5bd..ba4856a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -87,7 +87,7 @@  AC_CHECK_DECL([PRIdMAX],,
 
 dnl Checks for library functions.
 AC_CHECK_FUNCS(bsearch faccessat getpwnam getrlimit isalpha killpg \
-	       memfd_create mempcpy \
+	       memfd_create memrchr mempcpy \
 	       sigsetmask stpcpy strchrnul strsignal strtod strtoimax \
 	       strtoumax sysconf tee)
 
diff --git a/src/expand.c b/src/expand.c
index 6912e39..7b08e3d 100644
--- a/src/expand.c
+++ b/src/expand.c
@@ -1684,7 +1684,11 @@  static char *expmeta(char *name, unsigned name_len, size_t expdir_len)
 			cp = addfnamealt(enddir, expdir_len);
 		goto out_opendir;
 	}
+#ifdef HAVE_MEMRCHR
 	start = memrchr(name, '/', p - name);
+#else
+	start = strrchr(name, '/');
+#endif
 	if (start) {
 		c = *++start;
 		*start = 0;