Skip to content

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

Merged
CarterLi merged 1 commit into
fastfetch-cli:devfrom
pkubaj:freebsd-fix
Sep 21, 2026
Merged

CarterLi merged 1 commit into
fastfetch-cli:devfrom
pkubaj:freebsd-fix

Conversation

@pkubaj

@pkubaj pkubaj commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

Summary

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.

Checklist

  • I have tested my changes locally.

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`.
@CarterLi
CarterLi merged commit fd08fdb into fastfetch-cli:dev Sep 21, 2026
25 checks passed
@pkubaj
pkubaj deleted the freebsd-fix branch September 21, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants