strtonum(3) in FreeBSD?
Ted Unangst
tedu at zeitbombe.org
Wed Apr 13 19:20:59 PDT 2005
> Based on the man page, I see the following deficiencies:
> 1) No support for bases other than 10
it's meant for converting numbers, not addresses. if you want strtoaddr,
or strtomode_t, there's still strtol. the idea was to keep it simple.
most people think about sending 10 packets, not 0xa packets.
> 2) No provision to return the end of the converted string
exactly, there's no need for it. strtonum is used to convert a "string
containing a number" not a "string containing a number optionally followed
by some other things which are not the number". if strlen() won't give
you want you want, it means the input is not appropriate for strtonum.
> 3) No simple way to distinguish errors from a valid zero.
check errstr. i updated the man page to clearly reflect the fact it will
be NULL on sucess, that was the original intention.
the whole errno dance is there precisely because it's the only way to tell
if strtol failed and is so completely unnatural we want to insulate the
user from it.
i think you guys are missing the point of why strtonum exists. if it did
exactly what strtol does, why bother? strtol - #1 - #2 - #3 = strtonum.
strtonum came about because ping had a whole variety of issues with
numerical arguments. i created a strtonum function for it that was pretty
much special case. it doesn't take long to realize that there's also
ping6. and another thing. so the interface was widened up some. but not
too big. there was a lot of discussion about exactly what strtonum would
do, what it wouldn't do, and how one would use it. you don't have to
agree with our decisions, but it sounds like you're descending in on
"strtol but not called strtol".
--
someone's writing down your mistakes
someone's documenting your downfall
More information about the freebsd-current
mailing list