[PATCH] fix build on systems without memrchr(3)

Martijn Dekker <[email protected]>
Newsgroups org.kernel.vger.dash
Message-ID <[email protected]>
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).

-- 
||	modernish -- harness the shell
||	https://github.com/modernish/modernish
||
||	KornShell lives!
||	https://github.com/ksh93/ksh
memrchr.patch (text/plain, 855 B)
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;
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.