Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 Dec 2007 12:43:35 +1100 (EST)
From:      Bruce Evans <brde@optusnet.com.au>
To:        d@delphij.net
Cc:        freebsd-arch@freebsd.org
Subject:   Re: "Rational" way of getting a number in human readable form?
Message-ID:  <20071201121125.V15099@delplex.bde.org>
In-Reply-To: <47508B81.4090705@delphij.net>
References:  <47508B81.4090705@delphij.net>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20071201121125.V15099>