Implementation errors in strtol()

Garrett Wollman wollman at khavrinen.lcs.mit.edu
Sun Jan 23 19:17:36 PST 2005


<<On Fri, 21 Jan 2005 00:18:07 +0100, Matthias Andree <matthias.andree at gmx.de> said:

[Apologies for joining this discussion late; I was on vacation.]

> I do not have a place of discovery handy, but wasn't POSIX explicitly
> deferring in to the C standard and giving it precedence for any
> conflicts between the C standard library and POSIX?

POSIX/SUSv3 defers to C99.  However, POSIX significantly extends C99
by explicitly defining behavior that C99 leaves undefined or
implementation-defined.  In places where C is silent, POSIX is free to
make additional requirements on an implementation.

In the specific case of errors, POSIX observes the following three
principles (which you can find in the introductory material to either
XSI or XBD, I forget which):

- If POSIX says that function X "shall" set errno to a particular
value when a particular condition holds, implementations have no
freedom of action: they must detect that condition and set errno as
specified.

- If POSIX says that a function X "may" set errno to a particular
value when a particular condition holds, implementations are free not
to detect that condition, but if they do, they must set errno to that
value.

- Unless a function is specified as not setting errno, a function may
set errno to any nonzero value, regardless of whether it succeeds or
fails.

It then follows that:

- If a function detects an error condition which is not explicitly
enumerated in the standard, and which is not explicitly excluded by
the definition of that function, it may set errno to an
implementation-defined value and return an error indication.

-GAWollman



More information about the freebsd-current mailing list