[PATCH] replace memrchr with strrchr
Aiden Woodruff
aiden at aidenw.net
Fri Apr 3 03:27:20 UTC 2026
- ui-shared.c (cgit_set_title_from_path): remove memrchr which is less
widely available (e.g. it is missing on macOS) and replace with an
implementation that copies the path and uses strrchr.
Signed-off-by: Aiden Woodruff <aiden at aidenw.net>
---
I tested locally and the chevrons are correctly retained in the title along
with the path components. Although memrchr is in glibc, it is not available
everywhere and this patch was necessary for building on my system.
---
ui-shared.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/ui-shared.c b/ui-shared.c
index 219b830..a60b0a8 100644
--- a/ui-shared.c
+++ b/ui-shared.c
@@ -1244,17 +1244,19 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref,
void cgit_set_title_from_path(const char *path)
{
- struct strbuf sb = STRBUF_INIT;
- const char *slash, *last_slash;
-
if (!path)
return;
- for (last_slash = path + strlen(path); (slash = memrchr(path, '/', last_slash - path)) != NULL; last_slash = slash) {
+ struct strbuf sb = STRBUF_INIT;
+ char *slash, *last_slash, *path_copy = xstrdup(path);
+
+ for (last_slash = path_copy + strlen(path_copy); (slash = strrchr(path_copy, '/')) != NULL; last_slash = slash) {
strbuf_add(&sb, slash + 1, last_slash - slash - 1);
strbuf_addstr(&sb, " \xc2\xab ");
+ *slash = '\0';
}
- strbuf_add(&sb, path, last_slash - path);
+ strbuf_add(&sb, path_copy, last_slash - path_copy);
strbuf_addf(&sb, " - %s", ctx.page.title);
ctx.page.title = strbuf_detach(&sb, NULL);
+ free(path_copy);
}
--
2.50.1 (Apple Git-155)
More information about the CGit
mailing list