From owner-freebsd-arch Thu Jan 24 12:53: 5 2002 Delivered-To: freebsd-arch@freebsd.org Received: from mail.acns.ab.ca (mail.acns.ab.ca [142.179.151.95]) by hub.freebsd.org (Postfix) with ESMTP id 5FD0337B402 for ; Thu, 24 Jan 2002 12:52:59 -0800 (PST) Received: from colnta.acns.ab.ca (colnta.acns.ab.ca [192.168.1.2]) by mail.acns.ab.ca (8.11.6/8.11.3) with ESMTP id g0OKqoV02589 for ; Thu, 24 Jan 2002 13:52:50 -0700 (MST) (envelope-from davidc@colnta.acns.ab.ca) Received: (from davidc@localhost) by colnta.acns.ab.ca (8.11.6/8.11.3) id g0OKqoM00492 for arch@freebsd.org; Thu, 24 Jan 2002 13:52:50 -0700 (MST) (envelope-from davidc) Date: Thu, 24 Jan 2002 13:52:50 -0700 From: Chad David To: arch@freebsd.org Subject: strtod() Message-ID: <20020124135250.A454@colnta.acns.ab.ca> Mail-Followup-To: arch@freebsd.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i Sender: owner-freebsd-arch@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG After a short discussion with Alfred he recommended that I post my question here. On current (as of today) strtod() sets errno to EINVAL even when no error actually occurs. While I understand that the value of errno is undefined if an error does not occur, there is confusion when 0.0 is passed and the conversion is successful. SUSv2 states that if no conversion can be performed 0.0 is returned, and error MAY be set to EINVAL; as well, the Solaris interpretation of SUSv2 and c89 say: "3. If strtod() returns 0.0, one of the following occurred: a. The "subject sequence" was not an empty string, but evaluated to 0.0. (In this case, errno will be left unchanged.) b. The "subject sequence" was an empty string. (In this case, the Single UNIX Specification version 2 allows errno to be set to EINVAL or to be left unchanged. The C Standard does not specify any specific behavior in this case.) c. The "subject sequence" specified a numeric value that would cause a floating point underflow. (In this case, errno may be set to ERANGE or may be left unchanged.)" The usage notes all so say: "Because 0 is returned on error and is also a valid return on success, an application wishing to check for error situa- tions should set errno to 0, then call strtod(), then check errno and if it is non-zero, assume an error has occurred." I'm not saying that just because Solaris chooses to implement the interface in this way that FreeBSD should, but I do think that there is a lot of room for introducing (needless) complexity when porting applications from Solaris (like I am), and that while FreeBSD does not have to set EINVAL when an error occurs, it should NOT set it when an error does not occur. Note that on stable errno does not get set to EINVAL. Thanks. -- Chad David davidc@acns.ab.ca www.FreeBSD.org davidc@freebsd.org ACNS Inc. Calgary, Alberta Canada Fourthly, The constant breeders, beside the gain of eight shillings sterling per annum by the sale of their children, will be rid of the charge of maintaining them after the first year. - Johnathan Swift To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-arch" in the body of the message