diff options
| author | 2026-07-30 12:21:11 +0700 | |
|---|---|---|
| committer | 2026-07-30 12:21:11 +0700 | |
| commit | fbb76f0cb2d77b08e6ae02579dc2a549bff509a2 (patch) | |
| tree | 5e1392981ccbd452003f5029c7aa0de86d435b16 | |
| parent | 044821677c774cd24f25f1818ea51d09cc64b006 (diff) | |
| download | cgitext-fbb76f0cb2d77b08e6ae02579dc2a549bff509a2.tar.gz cgitext-fbb76f0cb2d77b08e6ae02579dc2a549bff509a2.zip | |
ui-shared: avoid the memrchr GNU extension
memrchr() is a GNU extension which glibc and musl provide but macOS does
not, so cgit_set_title_from_path() failed to compile there and the tree
could not be built on macOS at all.
Replace it with a small local helper. The search covers one path
component at a time, so there is nothing to gain from a libc version.
Signed-off-by: Saya Andy <saya.andy@posteo.com>
| -rw-r--r-- | ui-shared.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/ui-shared.c b/ui-shared.c index df52a9b..9f7625c 100644 --- a/ui-shared.c +++ b/ui-shared.c @@ -1247,6 +1247,17 @@ void cgit_print_snapshot_links(const struct cgit_repo *repo, const char *ref, strbuf_release(&filename); } +/* Locate the last '/' within the first len bytes of path, or NULL if + * there is none. Avoids memrchr(), which is a GNU extension. + */ +static const char *find_last_slash(const char *path, size_t len) +{ + while (len > 0) + if (path[--len] == '/') + return path + len; + return NULL; +} + void cgit_set_title_from_path(const char *path) { struct strbuf sb = STRBUF_INIT; @@ -1255,7 +1266,7 @@ 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) { + for (last_slash = path + strlen(path); (slash = find_last_slash(path, last_slash - path)) != NULL; last_slash = slash) { strbuf_add(&sb, slash + 1, last_slash - slash - 1); strbuf_addstr(&sb, " \xc2\xab "); } |