_POSIX_C_SOURCE and S_IFMT macros

Mateusz Guzik mjguzik at gmail.com
Mon Jan 25 09:17:55 UTC 2021


Does not matter what POSIX says. If something compiles on Linux, it
should compile on FreeBSD modulo use of Linux-specific APIs.

On 1/25/21, Xin Li via freebsd-standards <freebsd-standards at freebsd.org> wrote:
> Hi,
>
> I recently discovered [1] a difference between FreeBSD's handling of
> _POSIX_C_SOURCE and what I have observe on Linux and macOS systems,
> basically, if a program defines _POSIX_C_SOURCE to 200809L, but did not
> define _XOPEN_SOURCE, we will not define S_IFMT when sys/stat.h is
> included.
>
> It appears that the glibc version of sys/stat.h won't define it either,
> but their fcntl.h would define it by having _POSIX_C_SOURCE >= 200809L
> to define _USE_XOPEN2K8 and expose it.
>
> A quick glance on my Macbook suggests that they were defining the S_IFMT
> macros unconditionally.
>
> Based on my research, hiding these macros started in revision 40491 of
> CSRG repository (
> https://svnweb.freebsd.org/csrg?view=revision&revision=40491 ); NetBSD
> chose to make the macro visible when _XOPEN_SOURCE in revision 1.34 and
> expanded the visibility scope to also cover _NETBSD_SOURCE.
>
> Do we need to hide these with 200809L when _XOPEN_SOURCE is not defined?
>  If I'm reading the standards correctly, I think we are required to
> define these in modern POSIX revisions?
>
>
>
> [1] When building pigz (https://github.com/madler/pigz), I got:
>
> cc  -O3 -Wall -Wextra -Wno-unknown-pragmas -Wcast-qual -c pigz.c -o pigz.o
> pigz.c:3817:47: error: use of undeclared identifier 'S_IFMT'
>     if (stat(from, &st) != 0 || (st.st_mode & S_IFMT) != S_IFREG)
>                                               ^
> [...]
>
>
>


-- 
Mateusz Guzik <mjguzik gmail.com>


More information about the freebsd-standards mailing list