strtonum(3) in FreeBSD?

Ted Unangst tedu at zeitbombe.org
Thu Apr 14 17:58:35 PDT 2005


On Fri, 15 Apr 2005, Peter Jeremy wrote:

> The manpage states:
>   "The strtonum function was designed to facilitate safe, robust
>    programming and overcome the shortcomings of the atoi(3) and
>    strtol(3) family of interfaces."
> This implies (to me anyway) that it is a replacement for strtol(),
> though it only implements a subset of strtol() functionality.

yes, to make it simpler.

> This means you can't use it in a simple parser to handle the user
> entering "10k" to mean 10000 or "128m" to mean 128000000.  dd(1) needs
> this and I've used it on occasion.  Again, it's being sold as a
> replacement for strtol() but isn't.

pop quiz!  quick, how big is the file created by running "dd if=/dev/zero 
of=foo count=0x013b0x013b"?  no credit if you have to run the command to 
find out. :)

that's the kind of weirdness strtonum is designed to prevent.  of course, 
if you want the weirdness, strtonum is not for you.


-- 
we don't run washington and no one really does


More information about the freebsd-current mailing list