From owner-freebsd-arch@FreeBSD.ORG Sat Dec 1 07:21:30 2007 Return-Path: Delivered-To: freebsd-arch@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8840316A417 for ; Sat, 1 Dec 2007 07:21:30 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from fallbackmx09.syd.optusnet.com.au (fallbackmx09.syd.optusnet.com.au [211.29.132.242]) by mx1.freebsd.org (Postfix) with ESMTP id 6C81213C468 for ; Sat, 1 Dec 2007 07:21:29 +0000 (UTC) (envelope-from brde@optusnet.com.au) Received: from mail18.syd.optusnet.com.au (mail18.syd.optusnet.com.au [211.29.132.199]) by fallbackmx09.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id lB11hqpq031653 for ; Sat, 1 Dec 2007 12:43:52 +1100 Received: from c211-30-219-213.carlnfd3.nsw.optusnet.com.au (c211-30-219-213.carlnfd3.nsw.optusnet.com.au [211.30.219.213]) by mail18.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id lB11haTC030163 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sat, 1 Dec 2007 12:43:39 +1100 Date: Sat, 1 Dec 2007 12:43:35 +1100 (EST) From: Bruce Evans X-X-Sender: bde@delplex.bde.org To: d@delphij.net In-Reply-To: <47508B81.4090705@delphij.net> Message-ID: <20071201121125.V15099@delplex.bde.org> References: <47508B81.4090705@delphij.net> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-arch@freebsd.org Subject: Re: "Rational" way of getting a number in human readable form? X-BeenThere: freebsd-arch@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussion related to FreeBSD architecture List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Dec 2007 07:21:30 -0000 On Fri, 30 Nov 2007, Xin LI wrote: > It seems that we have some code getenv_quad() that accepts numbers in > "50M" "36G" alike form. Is it reasonable to add some sort of format > characters to vsscanf(9) so that it would be able to handle this, or is > it more appropriate to grow my own one? No. The scanf family shouldn't exist except for compatibility in userland, since it gives uncontrollable undefined behaviour on numeric overflow, so it is unusable except for reading certain character data. The strto*() family should be used for reading numeric data. Unfortunately, strtol(9) has a broken API -- errno doesn't exist in the kernel, but the strto*() family depends on it for reporting overflow. getenv_quad() has its own overflow bugs (blind multiplication by the scale factors...) and shouldn't exist for other reasons. Bruce