Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Jan 2021 23:46:47 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Kirk McKusick <mckusick@mckusick.com>
Cc:        Xin Li <delphij@delphij.net>, d@delphij.net, freebsd-standards@freebsd.org, Jilles Tjoelker <jilles@freebsd.org>, Ed Maste <emaste@freebsd.org>
Subject:   Re: _POSIX_C_SOURCE and S_IFMT macros
Message-ID:  <YA88R9rMSjHuASnU@kib.kiev.ua>
In-Reply-To: <202101252118.10PLISQI065263@chez.mckusick.com>
References:  <YA62oUzcLwL/bUNh@kib.kiev.ua> <202101252118.10PLISQI065263@chez.mckusick.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Jan 25, 2021 at 01:18:28PM -0800, Kirk McKusick wrote:
> > Date: Mon, 25 Jan 2021 14:16:33 +0200
> > From: Konstantin Belousov <kostikbel@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
> > 
> > On Mon, Jan 25, 2021 at 01:04:25AM -0800, Xin Li via freebsd-standards 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)
> >>                                               ^
> >> [...]
> > 
> > In my copy of IEEE Std 1003.1™-2017 S_IFMT and related S_IF<type> symbols
> > are specified as provided by sys/stat.h.  fcntl.h (not sys/fcntl.h, which
> > is not specified by POSIX at all) does not require export of S_IF*.
> > 
> > So I think S_IF symbols listed in POSIX standard should be provided by
> > sys/stat.h under some value of POSIX_C_SOURCE, but I did not dig to see
> > which should be the guard value.
> > 
> > Most likely 200809 is fine.
> 
> My reading of the current POSIX standard agrees with Kostik's analysis
> that S_IF symbols listed in POSIX standard should be provided by
> sys/stat.h. I do not have a complete set of POSIX standards over time,
> so cannot help with what the cutover date should be.

There is actually a small sign 'XSI' at line 13355 of C181.pdf.
This is what Jilles referenced as _XOPEN_SOURCE.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?YA88R9rMSjHuASnU>