Global (FreeBSD): fixes build when libc defines memrchr as a macro (#2599)

FreeBSD 16.0-CURRENT's <string.h> 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
<string.h> 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`.
This commit is contained in:
Piotr Kubaj
2026-09-21 06:21:57 +00:00
committed by GitHub
parent 203ccb31fa
commit fd08fdb9df
2 changed files with 3 additions and 0 deletions
+1
View File
@@ -85,6 +85,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 `<string.h>` defines `memrchr` as a qualifier-preserving function-like macro. (General, FreeBSD)
* Some internal cleanups and optimizations.
Logos:
+2
View File
@@ -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
}