From: Claudio Jeker Date: 2006-02-09T19:27:07+09:00 Subject: Re: boolean annoyance On Thu, Feb 09, 2006 at 09:52:33AM +0900, Logan Capaldo wrote: > > On Feb 8, 2006, at 7:41 PM, Claudio Jeker wrote: > > >This is not correct. strtol(3) does not return 0 in case of an > >error. It > >sets errno to ERANGE and returns LONG_MAX or LONG_MIN. > > RETURN VALUES > The strtol(), strtoll(), strtoimax() and strtoq() functions > return the > result of the conversion, unless the value would underflow or > overflow. > ***If no conversion could be performed, 0 is returned and the > global vari- > able errno is set to EINVAL.*** If an overflow or underflow > occurs, errno > is set to ERANGE and the function return value is clamped > according to > the following table. > > Emphasis (the triple *) mine. > Hmmm, my man page is a bit different: RETURN VALUES The strtol(), strtoll(), strtoimax(), and strtoq() functions returns the result of the conversion, unless the value would underflow or overflow. If overflow or underflow occurs, errno is set to ERANGE and the function return value is as follows: Function overflow underflow strtol() LONG_MIN LONG_MAX strtoll() LLONG_MIN LLONG_MAX strtoimax() INTMAX_MIN INTMAX_MAX strtoq() LLONG_MIN LLONG_MAX After googling a bit it looks like this is old BSD behaviour. A value of 0 plus EINVAL is returned if the base is bigger than 36 which is not checked in the original BSD code. /me grabs the dunce hat and stands in the corner for the rest of the day. -- :wq Claudio