From owner-freebsd-standards@freebsd.org Mon Jan 25 12:18:26 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 350BA4E02F6 for ; Mon, 25 Jan 2021 12:18:26 +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 4DPTRP5sY1z3sJn; Mon, 25 Jan 2021 12:18:25 +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 10PCGY9L023453 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Mon, 25 Jan 2021 14:16:37 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 10PCGY9L023453 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 10PCGXwi023452; Mon, 25 Jan 2021 14:16:33 +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 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 Message-ID: References: <69977864-0a68-909d-8ecb-1d72c0ec0ef9@delphij.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <69977864-0a68-909d-8ecb-1d72c0ec0ef9@delphij.net> 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: 4DPTRP5sY1z3sJn X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] 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 12:18:26 -0000 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.