From owner-freebsd-standards@freebsd.org Mon Jan 25 21:16:36 2021 Return-Path: Delivered-To: freebsd-standards@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 23FB64F1F93 for ; Mon, 25 Jan 2021 21:16:36 +0000 (UTC) (envelope-from mckusick@mckusick.com) Received: from chez.mckusick.com (chez.mckusick.com [70.36.157.235]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4DPjNM6Jgpz3MpV; Mon, 25 Jan 2021 21:16:35 +0000 (UTC) (envelope-from mckusick@mckusick.com) Received: from chez.mckusick.com (localhost [IPv6:::1]) by chez.mckusick.com (8.15.2/8.15.2) with ESMTP id 10PLISQI065263; Mon, 25 Jan 2021 13:18:28 -0800 (PST) (envelope-from mckusick@mckusick.com) Message-Id: <202101252118.10PLISQI065263@chez.mckusick.com> From: Kirk McKusick To: Xin Li Subject: Re: _POSIX_C_SOURCE and S_IFMT macros cc: d@delphij.net, freebsd-standards@freebsd.org, Jilles Tjoelker , Ed Maste , Konstantin Belousov X-URL: http://WWW.McKusick.COM/ Reply-To: Kirk McKusick In-reply-to: Comments: In-reply-to Konstantin Belousov message dated "Mon, 25 Jan 2021 14:16:33 +0200." MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <65261.1611609508.1@chez.mckusick.com> Content-Transfer-Encoding: quoted-printable Date: Mon, 25 Jan 2021 13:18:28 -0800 X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00,MISSING_MID, UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on chez.mckusick.com X-Rspamd-Queue-Id: 4DPjNM6Jgpz3MpV X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-Mailman-Approved-At: Tue, 26 Jan 2021 11:50:08 +0000 X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jan 2021 21:16:36 -0000 > Date: Mon, 25 Jan 2021 14:16:33 +0200 > From: Konstantin Belousov > To: d@delphij.net > Cc: freebsd-standards@freebsd.org, Jilles Tjoelker , > Ed Maste , Xin Li , > Marshall Kirk McKusick > 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 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