Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 13 Apr 2005 05:57:01 +1000
From:      Peter Jeremy <PeterJeremy@optushome.com.au>
To:        "R. Tyler Ballance" <tyler@tamu.edu>
Cc:        FreeBSD Current <freebsd-current@freebsd.org>
Subject:   Re: strtonum(3) in FreeBSD?
Message-ID:  <20050412195700.GN89047@cirb503493.alcatel.com.au>
In-Reply-To: <1113332762.27362.29.camel@localhost.localdomain>
References:  <1113332762.27362.29.camel@localhost.localdomain>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 2005-Apr-12 14:06:02 -0500, R. Tyler Ballance wrote:
>Quick, sort of, question. Is it worth it to bring strtonum(3) from
>OpenBSD into FreeBSD-CURRENT.

Based on the manpage, I'd suggest not.

>In theory, it should be a better implementation of what atoi(3) and
>strtol(3) do, but as tg@(mirbsd.org) pointed out to the OpenBSD fellows
>and myself, it doesn't take hexadecimal values well...

Based on the man page, I see the following deficiencies:
1) No support for bases other than 10
2) No provision to return the end of the converted string
3) No simple way to distinguish errors from a valid zero.

Based on the behaviour documented in the manpage, it's just as
difficult to use safely as atoi() or strtol().  The example given in
the man page relies on behaviour which is not documented in the man
page - namely that errstr is set to NULL on a successful conversion.
If this behaviour was documented then that would remove the third
point above and make it useful as a replacement for atoi() in some
cases.

-- 
Peter Jeremy



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