[PATCH] __FreeBSD_kernel__

Robert Millan rmh at debian.org
Sun Jul 3 15:37:31 UTC 2011


2011/7/3 Alexander Kabaev <kabaev at gmail.com>:
> __linux__ is exactly what __FreeBSD__ is and dies not identify kernel
> but rather Linux as whole OS, whatever that might be these days.
>
> There does not appear to be an universal macro that identifies
> environment as using Linux kernel regardless of the rest of components
> used (say, to identify Android and Ubuntu or something embedded with
> ucLibc as running Linux kernel with different userland
> implementations).

I think I'll cowardly try to stick to a practical POV and avoid the
discussion about names that tends to get people excited about :-)

So from a purely practical perspective:

- If __linux__ is defined, this implies you're using a specific kernel.
- If you're using that specific kernel, this implies __linux__ is defined.

which explains why using __linux__ to identify the kernel is useful
and reliable.

Can __linux__ be used to identify more things?  Most notably, can
__linux__ be used to identify userland API?

- If __linux__ is defined, this does not imply you're using GNU libc.
- If you're using GNU libc, this does not imply __linux__ is defined.

which explains why using __linux__ to identify libc is a bad idea.
However, it can be useful to identify a set of different C libraries
(Glibc, Bionic, uclibc, etc) if they share the property you're
interested in.

-- 
Robert Millan


More information about the freebsd-hackers mailing list