From owner-freebsd-current@FreeBSD.ORG Thu Apr 14 02:20:59 2005 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id ADCB616A4CE for ; Thu, 14 Apr 2005 02:20:59 +0000 (GMT) Received: from mail.codefusionis.com (ns.codefusionis.com [208.33.29.188]) by mx1.FreeBSD.org (Postfix) with SMTP id C9C2143D49 for ; Thu, 14 Apr 2005 02:20:56 +0000 (GMT) (envelope-from tedu@zeitbombe.org) Received: (qmail 32649 invoked by uid 1049); 14 Apr 2005 02:23:42 -0000 Received: from localhost (sendmail-bs@127.0.0.1) by localhost with SMTP; 14 Apr 2005 02:23:42 -0000 Date: Wed, 13 Apr 2005 22:23:42 -0400 (EDT) From: Ted Unangst X-X-Sender: tedu@ns.codefusionis.com To: tech@openbsd.org, freebsd-current@freebsd.org Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Mailman-Approved-At: Thu, 14 Apr 2005 12:07:06 +0000 Subject: Re: strtonum(3) in FreeBSD? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 14 Apr 2005 02:20:59 -0000 > Based on the man page, I see the following deficiencies: > 1) No support for bases other than 10 it's meant for converting numbers, not addresses. if you want strtoaddr, or strtomode_t, there's still strtol. the idea was to keep it simple. most people think about sending 10 packets, not 0xa packets. > 2) No provision to return the end of the converted string exactly, there's no need for it. strtonum is used to convert a "string containing a number" not a "string containing a number optionally followed by some other things which are not the number". if strlen() won't give you want you want, it means the input is not appropriate for strtonum. > 3) No simple way to distinguish errors from a valid zero. check errstr. i updated the man page to clearly reflect the fact it will be NULL on sucess, that was the original intention. the whole errno dance is there precisely because it's the only way to tell if strtol failed and is so completely unnatural we want to insulate the user from it. i think you guys are missing the point of why strtonum exists. if it did exactly what strtol does, why bother? strtol - #1 - #2 - #3 = strtonum. strtonum came about because ping had a whole variety of issues with numerical arguments. i created a strtonum function for it that was pretty much special case. it doesn't take long to realize that there's also ping6. and another thing. so the interface was widened up some. but not too big. there was a lot of discussion about exactly what strtonum would do, what it wouldn't do, and how one would use it. you don't have to agree with our decisions, but it sounds like you're descending in on "strtol but not called strtol". -- someone's writing down your mistakes someone's documenting your downfall