tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: strtonum(3) from OpenBSD?




Am 23.06.2009 um 23:14 schrieb Matthew Mondor:

On Tue, 23 Jun 2009 19:28:37 +0200
Adam Hoka <adam.hoka%gmail.com@localhost> wrote:

And what about implementing something with similar functionality sans the mentioned
api problems and put it into libutil?

Would OpenBSD and those few other programs also convert their code to
use a new interface though?  Otherwise we don't solve much...

Two possible draft alternatives are attached to fuel even more
debate (yes, seems I had too much time on my hands tonight :)  But
looking at how small these functions really are, maybe they're still
best embedded into the programs needing them?  Which if already
embedding strtonum() might best be left as-is.

So strtoint() uses intmax_t but doesn't allow to know if the supplied
value was too large or too small if out of range, as it uses standard
errno values.

On the other hand, strtoi() also using intmax_t provides an interface
with a custom error system (in this case it's still better than
strtonum() where this information was only human-readable, and its
optional error string could be provided via a localized and thread- safe function similar to strerror_r(), over-engineering for a simple problem
but allright for "correctness" :)

I see no point in inventing yet another string to integer conversion
function.  OpenBSD will for sure not change to that interface.

We have seen that TLS's argumentation was weak, if not wrong,
so why not use a function that is already there for a long time? Why
reinvent the wheel?

--
Matt
<strtoint.c><strtoi.c>



Home | Main Index | Thread Index | Old Index