Subject: Re: tales of woe from the recent tools/compat_defs.h pullups on netbsd-1-6
To: NetBSD Toolchain Technical Discussion List <tech-toolchain@NetBSD.ORG>
From: Luke Mewburn <>
List: tech-toolchain
Date: 06/23/2004 17:40:16
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Jun 23, 2004 at 03:02:44AM -0400, Greg A. Woods wrote:
  | [ On Tuesday, June 22, 2004 at 09:57:41 (+0200), Alan Barrett wrote: ]
  | > Subject: Re: tales of woe from the recent tools/compat_defs.h pullups=
 on netbsd-1-6
  | >
  | > strtoul() and friends are documented to set errno =3D ERANGE on overf=
  | > I had a quick look at the implementation, and don't see any obvious
  | > bugs.  So you should be able to do something like this:
  | >=20
  | > 	errno =3D 0;
  | > 	result =3D strtoul(...);
  | > 	if (result =3D=3D ULONG_MAX && errno =3D=3D ERANGE) {
  | > 	   ...
  | > 	}
  | Hmmm....  I suppose so.  I'm just _really_ leary about setting errno
  | before making a library call and then expecting it to only be changed
  | iff there's an error, even I use a "special" result in that way as a
  | hint to check errno only when it might be necessary to do so.

Well, that's the C99 & POSIX standard for you.

Per IEEE Std 1003.1, 2004 Edition for strtoul():
	Since 0, {ULONG_MAX}, and {ULLONG_MAX} are returned on error
	and are also valid returns on success, an application wishing
	to check for error situations should set errno to 0, then call
	strtoul() or strtoull(), then check errno.

strtod() and strtol() have similar statements.

  | (and thats without even considering the implications of errno in a
  | threaded environment!  ;-)

Don't the pthreads standards actually deal with the "special" case
that is errno, and provide it as a per-thread item that is a
modifiable int?


Content-Type: application/pgp-signature
Content-Disposition: inline

Version: GnuPG v1.2.4 (NetBSD)