Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Jan 2021 10:17:53 +0100
From:      Mateusz Guzik <mjguzik@gmail.com>
To:        d@delphij.net
Cc:        freebsd-standards@freebsd.org, Jilles Tjoelker <jilles@freebsd.org>,  Ed Maste <emaste@freebsd.org>, Xin Li <delphij@delphij.net>,  Marshall Kirk McKusick <mckusick@freebsd.org>
Subject:   Re: _POSIX_C_SOURCE and S_IFMT macros
Message-ID:  <CAGudoHGd%2B-Ga9AX429CsxJqVvbvRMek0w3OWdHC6o=DnMQH=SA@mail.gmail.com>
In-Reply-To: <69977864-0a68-909d-8ecb-1d72c0ec0ef9@delphij.net>
References:  <69977864-0a68-909d-8ecb-1d72c0ec0ef9@delphij.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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@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>



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAGudoHGd%2B-Ga9AX429CsxJqVvbvRMek0w3OWdHC6o=DnMQH=SA>