From owner-freebsd-standards@FreeBSD.ORG Sun May 18 21:50:53 2014 Return-Path: Delivered-To: freebsd-standards@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id C3C1A9AC; Sun, 18 May 2014 21:50:53 +0000 (UTC) Received: from mx1.stack.nl (relay02.stack.nl [IPv6:2001:610:1108:5010::104]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client CN "mailhost.stack.nl", Issuer "CA Cert Signing Authority" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 591322F38; Sun, 18 May 2014 21:50:53 +0000 (UTC) Received: from snail.stack.nl (snail.stack.nl [IPv6:2001:610:1108:5010::131]) by mx1.stack.nl (Postfix) with ESMTP id 535DB3592EF; Sun, 18 May 2014 23:50:50 +0200 (CEST) Received: by snail.stack.nl (Postfix, from userid 1677) id 3801B28497; Sun, 18 May 2014 23:50:50 +0200 (CEST) Date: Sun, 18 May 2014 23:50:50 +0200 From: Jilles Tjoelker To: Bruce Evans Subject: Re: standards/188316: Visibility of ntohl etc. and POSIX 2008 Message-ID: <20140518215050.GA8365@stack.nl> References: <201404061430.s36EUbFE092028@cgiserv.freebsd.org> <20140407024203.M6470@besplex.bde.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20140407024203.M6470@besplex.bde.org> User-Agent: Mutt/1.5.21 (2010-09-15) Cc: freebsd-gnats-submit@freebsd.org, freebsd-standards@freebsd.org, Christian Neukirchen X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 18 May 2014 21:50:53 -0000 On Mon, Apr 07, 2014 at 03:43:44AM +1000, Bruce Evans wrote: > On Sun, 6 Apr 2014, Christian Neukirchen wrote: > >> Description: > > According to POSIX 2008, the functions ntohl etc. are defined in > > > > (http://pubs.opengroup.org/onlinepubs/9699919799/functions/htonl.html), > > which works because they are defined unconditionally there. > > However, just including should also define them > > (http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/netinet_in.h.html): > >> The htonl(), htons(), ntohl(), and ntohs() functions shall be available > >> as described in . Inclusion of the header may > >> also make visible all symbols from . > POSIX.1-2001 also says this. > > But ntohl etc are inside a "#if !defined(_KERNEL) && __BSD_VISIBLE" > > in , violating the "shall be" requirement above. > The requirement was somehow missed before. Probably due to its bad wording. > The bad wording "shall be available" is only used for namespaces twice in > POSIX.1-2001-draft7 (for {h_errno} in and for {ntoh*} in > . The normal wording is "shall be defined as described in > "). > >> How-To-Repeat: > > echo '#include \nint main(){htonl(1);}' | cc -D_XOPEN_SOURCE=700 -x c - > > (all good) > > echo '#include \nint main(){htonl(1);}' | cc -D_XOPEN_SOURCE=700 -x c - > > :2:12: warning: implicit declaration of function 'htonl' is invalid in C99 [-Wimplicit-function-declaration] > > int main(){htonl(1);} > > ^ > > 1 warning generated. > >> Fix: > > Guard the definition with __POSIX_VISIBLE >= 200112. > This is wrong too, and is inconsistent with where there > the symbols are defined unconditionally (if this wouldn't be redundant). > The correctness of this depends on the symbols being in a header that > doesn't exist in versions of POSIX that don't have the symbols. I > think it is indeed correct, because POSIX started specifying both the > symbols and the headers in 2001. Howver, the unconditional declarations > may be wrong for XSI, and aren't really right for BSD. In 4.4BSD, they > were declared unconditionally in via nested pollution from > , and were only declared in the POSIX headers as a > side effect of these headers being broken unless the application included > . Similarly in FreeBSD-1 (and Net/2?). Applications written > for this polluted API are no longer supported. However, the documented > API (byteorder.3) was that these functions are declared in . > It is now that these functions are declared in the 2 POSIX headers. So you propose to change the "#if !defined(_KERNEL) && __BSD_VISIBLE" conditional to "#ifndef _KERNEL"? This affects only old versions of POSIX (where may not be included anyway) and non-POSIX standard C (which does not define either). Note that there are other __POSIX_VISIBLE >= 200112 conditionals in , so the submitter's change may be more consistent, even if it is somehow wrong. -- Jilles Tjoelker