Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Jan 2002 13:52:50 -0700
From:      Chad David <davidc@acns.ab.ca>
To:        arch@freebsd.org
Subject:   strtod()
Message-ID:  <20020124135250.A454@colnta.acns.ab.ca>

next in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020124135250.A454>