From 5554f32559657f03bbe6cf0b098528754ebdc82b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C5=8Dshin?= Date: Mon, 4 Dec 2023 19:23:28 -0500 Subject: [PATCH] add StrRChr, fix BaseName --- ape/loader.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ape/loader.c b/ape/loader.c index b65bd147f..13e6c5081 100644 --- a/ape/loader.c +++ b/ape/loader.c @@ -239,12 +239,11 @@ static int StrCmp(const char *l, const char *r) { return (l[i] & 255) - (r[i] & 255); } -static const char *BaseName(const char *s) { - int c; - const char *b = ""; +static const char *StrRChr(const char *s, int c) { + const char *b = 0; if (s) { - while ((c = *s++)) { - if (c == '/') { + for (; *s; ++s) { + if (*s == c) { b = s; } } @@ -252,6 +251,11 @@ static const char *BaseName(const char *s) { return b; } +static const char *BaseName(const char *s) { + const char *b = StrRChr(s, '/'); + return b ? b + 1 : s; +} + static void Bzero(void *a, unsigned long n) { long z; char *p, *e;