Re: Implementation errors in strtol()

From: Garrett Wollman <wollman_at_khavrinen.lcs.mit.edu>
Date: Sun, 23 Jan 2005 22:17:29 -0500 (EST)
<<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
Received on Mon Jan 24 2005 - 02:17:36 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:38:26 UTC