On platforms that have memrchr(), my_mrchr() maps to use that instead.
This is useful functionality, lacking on many platforms. This commit
also uses the new function in two places in the core where the comments
previously indicated it would be advantageous to use it if we had it.
It is left usable only in core, so that if this turns out to have been a
bad idea, it can be easily removed.
Anp |void |atfork_unlock
Apmb |I32 |my_lstat
pX |I32 |my_lstat_flags |NULLOK const U32 flags
+#if ! defined(HAS_MEMRCHR) && (defined(PERL_CORE) || defined(PERL_EXT))
+Exin |void * |my_memrchr |NN const char * s|const char c|const STRLEN len
+#endif
#if !defined(PERL_IMPLICIT_SYS)
Ap |I32 |my_pclose |NULLOK PerlIO* ptr
Ap |PerlIO*|my_popen |NN const char* cmd|NN const char* mode
#define validate_proto(a,b,c,d) Perl_validate_proto(aTHX_ a,b,c,d)
#define vivify_defelem(a) Perl_vivify_defelem(aTHX_ a)
#define yylex() Perl_yylex(aTHX)
+# if ! defined(HAS_MEMRCHR) && (defined(PERL_CORE) || defined(PERL_EXT))
+#define my_memrchr S_my_memrchr
+# endif
# if !defined(PERL_EXT_RE_BUILD)
# if defined(PERL_IN_REGCOMP_C)
#define _append_range_to_invlist(a,b,c) S__append_range_to_invlist(aTHX_ a,b,c)
return 1;
}
+#if ! defined (HAS_MEMRCHR) && (defined(PERL_CORE) || defined(PERL_EXT))
+
+PERL_STATIC_INLINE void *
+S_my_memrchr(const char * s, const char c, const STRLEN len)
+{
+ /* memrchr(), since many platforms lack it */
+
+ const char * t = s + len - 1;
+
+ PERL_ARGS_ASSERT_MY_MEMRCHR;
+
+ while (t >= s) {
+ if (*t == c) {
+ return (void *) t;
+ }
+ t--;
+ }
+
+ return NULL;
+}
+
+#endif
+
/*
* ex: set ts=8 sts=4 sw=4 et:
*/
libpath = SvPVX(libdir);
libpath_len = SvCUR(libdir);
- /* This would work more efficiently with memrchr, but as it's
- only a GNU extension we'd need to probe for it and
- implement our own. Not hard, but maybe not worth it? */
-
prefix = SvPVX(prefix_sv);
- lastslash = strrchr(prefix, '/');
+ lastslash = (char *) my_memrchr(prefix, '/',
+ SvEND(prefix_sv) - prefix);
/* First time in with the *lastslash = '\0' we just wipe off
the trailing /perl from (say) /usr/foo/bin/perl
SV *tempsv;
while ((*lastslash = '\0'), /* Do that, come what may. */
(libpath_len >= 3 && _memEQs(libpath, "../")
- && (lastslash = strrchr(prefix, '/')))) {
+ && (lastslash =
+ (char *) my_memrchr(prefix, '/',
+ SvEND(prefix_sv) - prefix))))
+ {
if (lastslash[1] == '\0'
|| (lastslash[1] == '.'
&& (lastslash[2] == '/' /* ends "/." */
# define my_strlcat Perl_my_strlcat
#endif
+#if defined(PERL_CORE) || defined(PERL_EXT)
+# ifdef HAS_MEMRCHR
+# define my_memrchr memrchr
+# else
+# define my_memrchr S_my_memrchr
+# endif
+#endif
+
#ifdef HAS_STRLCPY
# define my_strlcpy strlcpy
#else
PERL_CALLCONV int Perl_yyparse(pTHX_ int gramtype);
PERL_CALLCONV void Perl_yyquit(pTHX);
PERL_CALLCONV void Perl_yyunlex(pTHX);
+#if ! defined(HAS_MEMRCHR) && (defined(PERL_CORE) || defined(PERL_EXT))
+#ifndef PERL_NO_INLINE_FUNCTIONS
+PERL_STATIC_INLINE void * S_my_memrchr(const char * s, const char c, const STRLEN len);
+#define PERL_ARGS_ASSERT_MY_MEMRCHR \
+ assert(s)
+#endif
+#endif
#if !(defined(DEBUGGING))
# if !defined(NV_PRESERVES_UV)
# if defined(PERL_IN_SV_C)