From owner-freebsd-current Sun Mar 12 16:59:38 2000 Delivered-To: freebsd-current@freebsd.org Received: from mail.originative.co.uk (mailgate.originative.co.uk [194.217.50.228]) by hub.freebsd.org (Postfix) with ESMTP id BBB8E37B547 for ; Sun, 12 Mar 2000 16:59:34 -0800 (PST) (envelope-from paul@originative.co.uk) Received: from originative.co.uk (lobster.originative.co.uk [194.217.50.241]) by mail.originative.co.uk (Postfix) with ESMTP id 928211D132; Mon, 13 Mar 2000 00:59:27 +0000 (GMT) Message-ID: <38CC3D6F.73152D6D@originative.co.uk> Date: Mon, 13 Mar 2000 00:59:27 +0000 From: Paul Richards Organization: Originative Solutions Ltd X-Mailer: Mozilla 4.7 [en] (X11; I; FreeBSD 4.0-CURRENT i386) X-Accept-Language: en-GB, en MIME-Version: 1.0 To: Garrett Wollman Cc: keramida@ceid.upatras.gr, John Polstra , current@FreeBSD.ORG Subject: Re: MAX_UID ? References: <38CAD957.3C839375@originative.co.uk> <200003120430.UAA49807@vashon.polstra.com> <38CB322D.D12ED0B0@originative.co.uk> <20000313015009.A5653@hades.hell.gr> <38CC30FB.FC417909@originative.co.uk> <200003130018.TAA32652@khavrinen.lcs.mit.edu> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Garrett Wollman wrote: > > < said: > > > We could create a new include file that we use for constants that are > > related to FreeBSD specific types or we can agree on a coding style for > > performing bounds checking using tricks like ((uid_t)0-1) > > Or we can do it the right way, by assigning to a variable of the > correct type and checking that the value remains unchanged. I'm not just trying to determine whether a value fits into a type, I'm also trying to find out what the maximum value the type can hold is. e.g. in the following code snippet id = strtoul(p, (char **)NULL, 10); if (errno == ERANGE) { warnx("%s > max uid value (%lu)", p, ULONG_MAX); return (0); } you also have to print out the maximum value. Not an uncommon requirement for error reporting. You're solution doesn't help with the second part. What I'm looking at is the following. id = strtoul(p, (char **)NULL, 10); if ((errno == ERANGE) || (id >= ((uid_t)0-1))) { warnx("%s > max uid value (%lu)", p, ((uid_t)0-1)); return (0); } or the alternative id = strtoul(p, (char **)NULL, 10); if ((errno == ERANGE) || (id >= UID_MAX)) { warnx("%s > max uid value (%lu)", p, UID_MAX); return (0); } When you see it written out like that the latter is a lot more informative. It also provides the flexibility to limit the parameters max value even if the type allows it to be larger. This is of particular significance to UIDs which are currently limited to a far smaller value than would fit in a uid_t. Paul. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message