NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: lib/49429: Import strtonum(3)



The following reply was made to PR lib/49429; it has been noted by GNATS.

From: christos%zoulas.com@localhost (Christos Zoulas)
To: "Kamil Rytarowski" <n54%gmx.com@localhost>, gnats-bugs%NetBSD.org@localhost
Cc: 
Subject: Re: lib/49429: Import strtonum(3)
Date: Fri, 26 Dec 2014 21:01:16 -0500

 On Dec 27,  2:44am, n54%gmx.com@localhost ("Kamil Rytarowski") wrote:
 -- Subject: Re: lib/49429: Import strtonum(3)
 
 | >  4) do we really want ENOSUP this way?
 | 
 | strtoi(3)/strtou(3) will not work when someone might want to have code similar to this common idiom:
 | 
 | /* strtod example */
 | #include <stdio.h>      /* printf, NULL */
 | #include <stdlib.h>     /* strtod */
 | 
 | int main ()
 | {
 |   char szOrbits[] = "365.24 29.53";
 |   char* pEnd;
 |   double d1, d2;
 |   d1 = strtod (szOrbits, &pEnd);
 |   d2 = strtod (pEnd, NULL);
 |   printf ("The moon completes %.2f orbits per Earth year.\n", d1/d2);
 |   return 0;
 | }
 | 
 | http://www.cplusplus.com/reference/cstdlib/strtod/
 | 
 | I suggest that we will promote strtol(3)-like functions usage for checking for partial conversions.
 
 Sure they work, what do you mean? We return pEnd like strtod does, and
 the correct conversion value even on failure.
 
 | >  5) if base is not supported then we can unexpectedly abuse errno from EINVAL  and change return value from 0 to lo/hi
 | 
 | abuse errno and change it from EINVAL to ERANGE*
 
 Then we have to explain how our strtoi() is different than the rest of the
 family of functions.
 
 API design has tradeoffs..
 
 christos
 


Home | Main Index | Thread Index | Old Index