From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11473 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: Different behavior (strtod) between musl and glibc Date: Wed, 14 Jun 2017 13:26:41 -0400 Message-ID: <20170614172641.GG1627@brightrain.aerifal.cx> References: <87d1a63cql.fsf@oldenburg.str.redhat.com> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1497461221 21483 195.159.176.226 (14 Jun 2017 17:27:01 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 14 Jun 2017 17:27:01 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) Cc: Xiaowei Zhan , musl@lists.openwall.com To: Florian Weimer Original-X-From: musl-return-11486-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jun 14 19:26:57 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dLC4H-0005KX-6R for gllmg-musl@m.gmane.org; Wed, 14 Jun 2017 19:26:57 +0200 Original-Received: (qmail 22295 invoked by uid 550); 14 Jun 2017 17:26:59 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 22274 invoked from network); 14 Jun 2017 17:26:58 -0000 Content-Disposition: inline In-Reply-To: <87d1a63cql.fsf@oldenburg.str.redhat.com> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11473 Archived-At: On Wed, Jun 14, 2017 at 03:44:34PM +0200, Florian Weimer wrote: > Xiaowei Zhan writes: > > > I notice that when pass a non-numeric char to strtod, musl will set > > errno to non-zero, but glibc will set errno to zero. I am curious why > > this difference exists, and whether it is necessary to make strtod in > > musl behave similarly to glibc. > > I think glibc leaves errno at zero; it does not set it. For input which > cannot be converted, this seems to be the behavior mandated by C11. > POSIX describes the EINVAL value as an extension to the C standard. > glibc does not appear to implement this extension. > > So both behaviors are correct. CX is a normative requirement for POSIX conformance; it indicates a requirement beyond (but not conflicting with) the C requirements for an interface defined by C. However, it's a "may fail", not a "shall fail", so the error is optional, and thus you're right that both musl and glibc are correct on the matter. I think you're also correct that glibc leaves errno alone in this case. Setting it to 0 would be non-conforming. The implementation is never permitted to set errno to 0 except at initial program entry. Rich