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 <lukem@NetBSD.org>
List: tech-toolchain
Date: 06/23/2004 17:40:16
--lR6P3/j+HGelbRkf
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=
low.
  | > 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) {
  | > 	   ...
  | > 	}
  |=20
  | 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?



Cheer,
Luke.

--lR6P3/j+HGelbRkf
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (NetBSD)

iD8DBQFA2TPgpBhtmn8zJHIRAnAoAKDQfMHXKjdd40Y0ovDU33z5ZwNr+gCdG9FF
sJNiqju/+r/IVo63gU2+s3Q=
=wzj4
-----END PGP SIGNATURE-----

--lR6P3/j+HGelbRkf--