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

next in thread | previous in thread | raw e-mail | index | archive | help
> 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 w=
rote:
>> 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 incl=
uded.
>> =

>> 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 >=3D 200809=
L
>> to define _USE_XOPEN2K8 and expose it.
>> =

>> A quick glance on my Macbook suggests that they were defining the S_IFM=
T
>> macros unconditionally.
>> =

>> Based on my research, hiding these macros started in revision 40491 of
>> CSRG repository (
>> https://svnweb.freebsd.org/csrg?view=3Drevision&revision=3D40491 ); Net=
BSD
>> 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 pig=
z.o
>> pigz.c:3817:47: error: use of undeclared identifier 'S_IFMT'
>>     if (stat(from, &st) !=3D 0 || (st.st_mode & S_IFMT) !=3D S_IFREG)
>>                                               ^
>> [...]
> =

> In my copy of IEEE Std 1003.1=E2=84=A2-2017 S_IFMT and related S_IF<type=
> symbols
> are specified as provided by sys/stat.h.  fcntl.h (not sys/fcntl.h, whic=
h
> 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.

	Kirk McKusick



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