[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: strtonum(3) from OpenBSD?
On Fri, Jun 26, 2009 at 06:20:15PM +0000, David Holland wrote:
> Unless strtol is specifically granted permission to clear errno to 0
> after calling other functions, which it isn't in C99 (don't have POSIX
> on hand) there's a problem.
The POSIX version is explicit that it will not touch errno on success.
It also gives explicitly the errno = 0 + strtol idiom.
> There's also possibly an issue that C99 does not specifically say that
> endptr is set on the overflow failure case, so in principle one ought
> to test for that case before touching it. (Which is also unlike the
> example in strtol(3).)
I would expect a correct implementation of strtol to set endptr either
to the point of overflow or the first non-digit. I am not sure if the
standard requires full processing of the input or not for the overflow
> It's too bad they didn't define the overflow case to return with
> endptr pointing at a digit. That would make things a lot easier in the
> common cases.
I don't think so. Overflow is detected by errno value, period. I think
you want to make the interface worse than it is for no good reason.
> What if some failing (and defective) internal call leaves a trap
> representation in errno?
I can't find anything in the C standard that allows setting errno for
Main Index |
Thread Index |