From owner-freebsd-standards@FreeBSD.ORG Sun May 18 22:00:01 2014 Return-Path: Delivered-To: freebsd-standards@smarthost.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 9A161B29 for ; Sun, 18 May 2014 22:00:01 +0000 (UTC) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:1900:2254:206c::16:87]) (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 870A42F77 for ; Sun, 18 May 2014 22:00:01 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.8/8.14.8) with ESMTP id s4IM01lR074042 for ; Sun, 18 May 2014 22:00:01 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.8/8.14.8/Submit) id s4IM013Z074041; Sun, 18 May 2014 22:00:01 GMT (envelope-from gnats) Date: Sun, 18 May 2014 22:00:01 GMT Message-Id: <201405182200.s4IM013Z074041@freefall.freebsd.org> To: freebsd-standards@FreeBSD.org Cc: From: Jilles Tjoelker Subject: Re: standards/188316: Visibility of ntohl etc. and POSIX 2008 Reply-To: Jilles Tjoelker 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 22:00:01 -0000 The following reply was made to PR standards/188316; it has been noted by GNATS. From: Jilles Tjoelker To: Bruce Evans Cc: Christian Neukirchen , freebsd-gnats-submit@freebsd.org, freebsd-standards@freebsd.org Subject: Re: standards/188316: Visibility of ntohl etc. and POSIX 2008 Date: Sun, 18 May 2014 23:50:50 +0200 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