From owner-freebsd-standards@freebsd.org Mon Jan 25 21:47:10 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 B89634F2DC8 for ; Mon, 25 Jan 2021 21:47:10 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4DPk3f0bgLz3PhF; Mon, 25 Jan 2021 21:47:09 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 10PLkmgW059926 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 25 Jan 2021 23:46:51 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 10PLkmgW059926 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 10PLkmb7059925; Mon, 25 Jan 2021 23:46:48 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Mon, 25 Jan 2021 23:46:47 +0200 From: Konstantin Belousov To: Kirk McKusick Cc: Xin Li , d@delphij.net, freebsd-standards@freebsd.org, Jilles Tjoelker , Ed Maste Subject: Re: _POSIX_C_SOURCE and S_IFMT macros Message-ID: References: <202101252118.10PLISQI065263@chez.mckusick.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <202101252118.10PLISQI065263@chez.mckusick.com> X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on tom.home X-Rspamd-Queue-Id: 4DPk3f0bgLz3PhF X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com X-Spamd-Result: default: False [-2.99 / 15.00]; ARC_NA(0.00)[]; RBL_DBL_DONT_QUERY_IPS(0.00)[2001:470:d5e7:1::1:from]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; NEURAL_HAM_LONG(-1.00)[-1.000]; MIME_GOOD(-0.10)[text/plain]; HAS_XAW(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; R_SPF_SOFTFAIL(0.00)[~all:c]; RCPT_COUNT_FIVE(0.00)[6]; SPAMHAUS_ZRD(0.00)[2001:470:d5e7:1::1:from:127.0.2.255]; TO_MATCH_ENVRCPT_SOME(0.00)[]; NEURAL_HAM_SHORT(-0.99)[-0.992]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; MIME_TRACE(0.00)[0:+]; MAILMAN_DEST(0.00)[freebsd-standards]; RCVD_COUNT_TWO(0.00)[2] 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:47:10 -0000 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 > > 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 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 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.