Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Jan 2021 01:04:25 -0800
From:      Xin Li <delphij@delphij.net>
To:        freebsd-standards@freebsd.org, Jilles Tjoelker <jilles@FreeBSD.org>, Ed Maste <emaste@FreeBSD.org>
Cc:        Marshall Kirk McKusick <mckusick@freebsd.org>
Subject:   _POSIX_C_SOURCE and S_IFMT macros
Message-ID:  <69977864-0a68-909d-8ecb-1d72c0ec0ef9@delphij.net>

next in thread | raw e-mail | index | archive | help
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
--3HCik9fKRoooaqEco88ihSK1eM5qKyEZj
Content-Type: multipart/mixed; boundary="91OnLhtfkkNYnIHeNGLSbk1DS1MEbU2W9";
 protected-headers="v1"
From: Xin Li <delphij@delphij.net>
Reply-To: d@delphij.net
To: freebsd-standards@freebsd.org, Jilles Tjoelker <jilles@FreeBSD.org>,
 Ed Maste <emaste@FreeBSD.org>
Cc: Marshall Kirk McKusick <mckusick@freebsd.org>
Message-ID: <69977864-0a68-909d-8ecb-1d72c0ec0ef9@delphij.net>
Subject: _POSIX_C_SOURCE and S_IFMT macros

--91OnLhtfkkNYnIHeNGLSbk1DS1MEbU2W9
Content-Type: text/plain; charset=utf-8
Content-Language: en-US
Content-Transfer-Encoding: quoted-printable

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 includ=
ed.

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 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=3Drevision&revision=3D40491 ); NetBS=
D
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) !=3D 0 || (st.st_mode & S_IFMT) !=3D S_IFREG)
                                              ^
[...]



--91OnLhtfkkNYnIHeNGLSbk1DS1MEbU2W9--

--3HCik9fKRoooaqEco88ihSK1eM5qKyEZj
Content-Type: application/pgp-signature; name="OpenPGP_signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="OpenPGP_signature"

-----BEGIN PGP SIGNATURE-----

wsF5BAABCAAjFiEEceNg5NEMZIki80nQQHl/fJX0g08FAmAOiZkFAwAAAAAACgkQQHl/fJX0g0+I
EhAAnzcCPtyTeC1Uj40yVGsKbgZ9Xt1xVfUPGlEREJDkOvy7md0tHrNVgjb+Apqjxoz6kbPKtTUr
zf5kiJK+vpQ0ocPZoDtG8NNyMEwG0CFCipu9QEw1cBNEq3kfDEaEJb4wfiSUvmFsBDWFpBkq/YPQ
Vjv0cln24ydzr9Dw0yTv7+z49EVsg0GwL+t8954SuEBMqbBIvr6Yi9g7E9ZxuL3yOdFkUttF4Yf0
eUNjB2WmAko33jGIAitHzW6zIFheo6EG+57GyHpWRX0lhQRR8Wqx3YFJSShWrJsxzDsxD7rneqAY
N4n0/d6Ek0jKjHBb2TZdB2Zm15T7GTOgoeAZUcumvjHJFoFYjBJjamJGcHZOaDT28vxluVLQQdmc
joFyXIwNoENqKJYtjyAtIXPrby7WdfvVxfR8mFrIitH79IpfbKTrPZSxPhG49lWCvy0x3/++VKo2
7jKAzPdoZShFgAe1hjZRqVZuY4lWXYvUrVZL7IR7CCB8J1VjmKwiIO6cgCX/A1w1KV5ECSDyeDlL
Pdbtixi00IMOqjsiBb8hzfTtPLbBxbCJh6oQP5SuE+kv5f2yUV/6OIlgAiK3hy6A9N//zDUmqFOF
nO5axK0R+xOruGxdYO/7pp8+0d4gwC8uYssCCErQ5ixl6KkSt7mBHwx9FTMqb3BAPn1McicEshKs
R9o=
=+bO/
-----END PGP SIGNATURE-----

--3HCik9fKRoooaqEco88ihSK1eM5qKyEZj--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69977864-0a68-909d-8ecb-1d72c0ec0ef9>