From 28bd0220453f31193064cd3b70c94439c2ede7f6 Mon Sep 17 00:00:00 2001 From: Piotr Kubaj Date: Sun, 20 Sep 2026 20:57:52 +0200 Subject: [PATCH] Global (FreeBSD): fixes build when libc defines `memrchr` as a macro FreeBSD 16.0-CURRENT's now provides C23-style qualifier-preserving wrappers for the string search functions. Besides the prototype, `memrchr` (like `memchr`, `strchr`, `strstr`, `memmem`, ...) is also defined as a function-like macro built on `_Generic`: #define memrchr(b, c, n) __qualsel((b), \ (const void *)(memrchr)((b), (c), (n)), (memrchr)((b), (c), (n))) `common/memrchr.h` redeclares the function unconditionally. When has already been included, that declaration is expanded by the macro and every translation unit fails with: src/common/memrchr.h:11:7: error: expected identifier or '(' 11 | void* memrchr(const void* s, int c, size_t n); A libc that defines `memrchr` as a macro has necessarily declared the function it wraps, so skip our declaration in that case. Nothing changes on platforms where `memrchr` is not a macro, and the fallback implementation is still selected by `check_function_exists`. --- CHANGELOG.md | 1 + src/common/memrchr.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bde10a435e..db6c4b048b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -84,6 +84,7 @@ Bugfixes: * Fixed `{#keys}` and `{#title}` in module format strings not honoring the `brightColor` display option. (Format) * Fixed `paddingTop` and `paddingLeft` being ignored by the `kitty-icat` image logo type. (Logo) * Fixed issues when running on big-endian platforms. +* Fixed building on FreeBSD 16.0-CURRENT, where `` defines `memrchr` as a qualifier-preserving function-like macro. (General, FreeBSD) * Some internal cleanups and optimizations. Logos: diff --git a/src/common/memrchr.h b/src/common/memrchr.h index 6905a33176..9d4ef24aa0 100644 --- a/src/common/memrchr.h +++ b/src/common/memrchr.h @@ -8,7 +8,9 @@ extern "C" { // `memrchr` is a GNU extension and may not be declared by system headers even when the symbol exists. // Declare it unconditionally; the build system provides a fallback implementation when missing. +#ifndef memrchr void* memrchr(const void* s, int c, size_t n); +#endif #ifdef __cplusplus }