tech-userlevel archive

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

Re: strtonum(3) from OpenBSD?

Am 24.06.2009 um 21:44 schrieb Steven M. Bellovin:

On Wed, 24 Jun 2009 21:00:53 +0200
Marc Balmer <> wrote:

Am 24.06.2009 um 20:34 schrieb Steven M. Bellovin:

On Wed, 24 Jun 2009 14:24:53 -0400
Thor Lancelot Simon <> wrote:

The function generates errno values which can't be used to
distinguish the error cases distinguished by the text strings,
which are (absurdly) specified in its manual page as part of the
API (in other words, the function as specified is inherently

If it didn't set errno at all, it would be an example of really,
really bad API design.  Since it does (but doesn't do so usefully),
it's merely an example of bad API design.

This is NetBSD.  Cleanliness matters.  I'm opposed to adding this
API to the system in its current form.

I'd have phrased it differently, but I agree with Thor -- this is
a bad
API.  Nor have I seen sufficient evidence that it's widely used in
software we might want to import.

I am eager to learn why it is bad.

The primary issue is that it returns a text string for error
indications, with all the implications for localization and consistency
of style.  It's like the Caliph is alleged to have said about the

it comfortably sets the errno variable.  the errstr argument can be
set to NULL; then it will not be set and can thus be ignored.

Library of Alexandria -- if the information is consistent with errno,
it's unnecessary; if it's inconsistent, it's evil.  (For the story of
the Caliph and the Library -- and a pretty thorough debunking of it --

I could cite some works of cicero here, but I think that would
be a bit unfair since poor cicero had no C compiler to play with
while in his exile in romania....

                --Steve Bellovin,

Home | Main Index | Thread Index | Old Index