Diff options
Diffstat (limited to 'source/ui-shared.c')
| -rw-r--r-- | source/ui-shared.c | 27 |
1 file changed, 7 insertions, 20 deletions
diff --git a/source/ui-shared.c b/source/ui-shared.c index 1cf53d4..eb57497 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -704,18 +704,6 @@ static void print_path_crumbs(char *path) ctx.qry.path = old_path; } -/* - * A reverse memchr, which glibc has as memrchr but macOS and the BSDs do not. - */ -static const char *find_last_char(const char *start, const char *end, int c) -{ - while (end > start) { - if (*--end == c) - return end; - } - return NULL; -} - static void vprint_error(const char *fmt, va_list ap) { html("<div class='error'>"); @@ -1855,21 +1843,20 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, co void cgit_set_title_from_path(const char *path) { struct strbuf sb = STRBUF_INIT; - const char *slash, *last_slash; + char *rest, *slash; if (!path) return; // The path is read from the end so that the title names the file first // and the directories it sits in after it. - last_slash = path + strlen(path); - while ((slash = find_last_char(path, last_slash, '/'))) { - strbuf_add(&sb, slash + 1, last_slash - slash - 1); - strbuf_addstr(&sb, " < "); - last_slash = slash; + rest = xstrdup(path); + while ((slash = strrchr(rest, '/'))) { + strbuf_addf(&sb, "%s < ", slash + 1); + *slash = '\0'; } - strbuf_add(&sb, path, last_slash - path); - strbuf_addf(&sb, " - %s", ctx.page.title); + strbuf_addf(&sb, "%s - %s", rest, ctx.page.title); + free(rest); ctx.page.title = strbuf_detach(&sb, NULL); } |
