Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Apr 2005 21:01:26 -0400 (EDT)
From:      Ted Unangst <tedu@zeitbombe.org>
To:        Peter Jeremy <PeterJeremy@optushome.com.au>
Cc:        freebsd-current@freebsd.org
Subject:   Re: strtonum(3) in FreeBSD?
Message-ID:  <Pine.BSO.4.61.0504142058080.29873@af.pbqrshfvbavf.pbz>
In-Reply-To: <20050414210840.GT89047@cirb503493.alcatel.com.au>
References:  <Pine.BSO.4.61.0504132206030.18943@af.pbqrshfvbavf.pbz> <20050414210840.GT89047@cirb503493.alcatel.com.au>

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



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