From owner-freebsd-current@FreeBSD.ORG Thu Apr 14 21:08:50 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 6589816A4CF for ; Thu, 14 Apr 2005 21:08:50 +0000 (GMT) Received: from mail02.syd.optusnet.com.au (mail02.syd.optusnet.com.au [211.29.132.183]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7D3E743D39 for ; Thu, 14 Apr 2005 21:08:49 +0000 (GMT) (envelope-from PeterJeremy@optushome.com.au) Received: from cirb503493.alcatel.com.au (c211-30-75-229.belrs2.nsw.optusnet.com.au [211.30.75.229]) j3EL8fEA011747 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO); Fri, 15 Apr 2005 07:08:47 +1000 Received: from cirb503493.alcatel.com.au (localhost.alcatel.com.au [127.0.0.1])j3EL8f7l003678; Fri, 15 Apr 2005 07:08:41 +1000 (EST) (envelope-from pjeremy@cirb503493.alcatel.com.au) Received: (from pjeremy@localhost)j3EL8eMZ003677; Fri, 15 Apr 2005 07:08:40 +1000 (EST) (envelope-from pjeremy) Date: Fri, 15 Apr 2005 07:08:40 +1000 From: Peter Jeremy To: Ted Unangst Message-ID: <20050414210840.GT89047@cirb503493.alcatel.com.au> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4.2i cc: tech@openbsd.org cc: freebsd-current@freebsd.org 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 21:08:50 -0000 On Wed, 2005-Apr-13 22:23:42 -0400, Ted Unangst wrote: >> 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. The manpage states: "The strtonum function was designed to facilitate safe, robust programming and overcome the shortcomings of the atoi(3) and strtol(3) family of interfaces." This implies (to me anyway) that it is a replacement for strtol(), though it only implements a subset of strtol() functionality. >> 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. This means you can't use it in a simple parser to handle the user entering "10k" to mean 10000 or "128m" to mean 128000000. dd(1) needs this and I've used it on occasion. Again, it's being sold as a replacement for strtol() but isn't. >> 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. I suspected so but that needs to be clearly documented. >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". I think strtonum() is a good atoi() family replacement. It's not a general replacement for strtol() but the man page doesn't distinguish between atoi() and strtol(). If the manpage stated that it was an atoi() replacement and only referenced strtol() as a side-note then my first two objections would vanish. Note that there are cases in the tree (I've found one in apmd(8)) where atoi() is passed a string that is known to have trailing non-numeric characters that should be ignored. Removing the trailing characters would make the lexer more complex. -- Peter Jeremy