Subject: Re: strtonum(3) in our libc
To: Jason Thorpe <thorpej@shagadelic.org>
From: Mindaugas <unex@linija.org>
List: tech-userlevel
Date: 06/06/2006 00:33:51
Jason Thorpe <thorpej@shagadelic.org> wrote:
> 1- How do you do error detection?  Looks like you check for return  
> value of zero and a non-zero errno?  This is bogus.  It should
> return 0 on success and an error code on failure.  The result should
> be passed back by the caller providing a pointer.
We should check the **errstrp value. If NULL - we have an error.
Passing back the result with a pointer (and returning error code) could
be more rational, but in fact, there are no technically difference
between these ways.

> 3- It does not handle unsigned conversions.  If we're going to keep  
> the same naming convention, it should be "strtoinum()" and "strtounum 
> ()" (following strtoimax(3) and strotoumax(3)).
Well, sounds good.

> 4- It should not produce "long long" results.  It should produce a  
> "intmax_t" or "uintmax_t" (depending on if we're doing a signed or  
> unsigned conversion).
Agree.

> Furthermore, the way that the error string is optionally returned is  
> not very internationalization-friendly.
Agree, it should return error codes instead of string.

> 2- It does not take a base argument.
Well, position explaination of OpenBSD folks starting here:
http://lists.freebsd.org/pipermail/freebsd-current/2005-April/048744.html
http://lists.freebsd.org/pipermail/freebsd-current/2005-April/048745.html

And I think here is the main problem. Main point of this function
addition is a compability purposes with OpenBSD and their projects
which uses it. Both the FreeBSD folks and we agree, that API could be
improved, but OpenBSD folks, as usually, don not. So at first we must
take a decision:
a) Improve this function and somehow stay compatible with original
implementation
b) Add the original function into the libc wihout changes, as FreeBSD
team did
c) Do not add this function at all


-- 
Best regards,
Mindaugas