Skip to content

fix: don't define _POSIX_C_SOURCE on FreeBSD - #285

Open
weanty0 wants to merge 3 commits into
tsoding:mainfrom
weanty0:main
Open

weanty0 wants to merge 3 commits into
tsoding:mainfrom
weanty0:main

Conversation

@weanty0

@weanty0 weanty0 commented Nov 15, 2026 •

Copy link
Copy Markdown

closes #284
(read the issue for all of da details)

Checking if FreeBSD is defined before defining _POSIX_C_SOURCE and skipping definition if yes, does not turn __BSD_VISIBLE off. This smol fix ensures that _SC_NPROCESSORS_ONLN is still defined in <unistd.h>.

Another possible fix:
Keep the _POSIX_C_SOURCE define everywhere and use sysctl on bsds that hide _SC_NPROCESSORS_ONLN (FreeBSD, NetBSD, DragonFly):

#elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__)
    int mib[2] = { CTL_HW, HW_NCPU };
    int n = 0;
    size_t len = sizeof(n);
    if (sysctl(mib, 2, &n, &len, NULL, 0) < 0 || n < 1) return 1;
    return n;

, this needs <sys/param.h> and <sys/sysctl.h> defined on netbsd and dragonfly.

@weanty0
weanty0 marked this pull request as draft November 18, 2026 07:47
@weanty0
weanty0 marked this pull request as ready for review November 18, 2026 08:11
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.

nob.c fails to compile on FreeBSD

1 participant