summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPer Buer <per.buer@gmail.com>2026-09-10 20:39:50 +0200
committerPer Buer <per.buer@gmail.com>2026-09-10 20:39:50 +0200
commit209395ed9cffb42f4c479a8d426a173b9e50ab4f (patch)
treea47916e387017629ba7d14251b979a6c1debe4e7
parent044821677c774cd24f25f1818ea51d09cc64b006 (diff)
ui-shared: avoid memrchr(), a GNU extension
memrchr() is not in POSIX and is missing on macOS, where it breaks the build of cgit_set_title_from_path(). Scan backwards for the separator by hand instead; the path components handed to this function are short enough that the difference does not matter. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
-rw-r--r--ui-shared.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/ui-shared.c b/ui-shared.c
index df52a9b..27a60ac 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1255,9 +1255,18 @@ void cgit_set_title_from_path(const char *path)
if (!path)
return;
- for (last_slash = path + strlen(path); (slash = memrchr(path, '/', last_slash - path)) != NULL; last_slash = slash) {
+ /* memrchr() is a GNU extension, so find the last '/' by hand. */
+ last_slash = path + strlen(path);
+ for (;;) {
+ slash = last_slash;
+ while (slash > path && slash[-1] != '/')
+ slash--;
+ if (slash == path)
+ break;
+ slash--;
strbuf_add(&sb, slash + 1, last_slash - slash - 1);
strbuf_addstr(&sb, " \xc2\xab ");
+ last_slash = slash;
}
strbuf_add(&sb, path, last_slash - path);
strbuf_addf(&sb, " - %s", ctx.page.title);