History log of /freebsd-10.1-release/lib/libutil/expand_number.c
Revision Date Author Comments
(<<< Hide modified files)
(Show modified files >>>)
# 272461 02-Oct-2014 gjb

Copy stable/10@r272459 to releng/10.1 as part of
the 10.1-RELEASE process.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation

# 256281 10-Oct-2013 gjb

Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.

Approved by: re (implicit)
Sponsored by: The FreeBSD Foundation


# 255069 30-Aug-2013 pluknet

The round of expand_number() cleanups.
o Fix range error checking to detect overflow when uint64_t < uintmax_t.
o Remove a non-functional check for no valid digits as pointed out by Bruce.
o Remove a rather pointless comment describing what the function does.
o Clean up a bunch of style bugs.

Brucified by: bde


# 254621 21-Aug-2013 pluknet

Reset errno before strtoumax() call to properly detect ERANGE.
Restore saved errno if strtoumax() call is successful.

Reported by: ache
Reviewed by: jilles
MFC after: 1 week


# 254600 21-Aug-2013 pluknet

Check strtoumax(3) for ERANGE in case of non-prefixed string.

OK'd by: silence on current@
MFC after: 1 week


# 211343 15-Aug-2010 des

Further simplify the code, and update the manpage.

Submitted by: Christoph Mallon <christoph.mallon@gmx.de>


# 211338 15-Aug-2010 des

no-op commit to note that the example given in the previous commit is
a very bad one, since the shift does not actually overflow. This is
a better example (assuming uint64_t = unsigned long long):

~0LLU >> 9 = 0x7fffffffffffffLLU
~0LLU >> 9 << 10 = 0xfffffffffffffc00LLU
~0LLU >> 9 << 10 >> 10 = 0x3fffffffffffffLLU


# 211337 15-Aug-2010 des

Fix the overflow test. It is possible for the result of an
overflowing shift to be larger than the original value, e.g.

(uint64_t)1 << 53 = 0x20000000000000
((uint64_t)1 << 53) << 10 = 0x8000000000000000


# 211304 14-Aug-2010 des

Simplify expand_number() by combining the (unrolled) loop with the
switch. Since expand_number() does not accept negative numbers, switch
from int64_t to uint64_t; this makes it easier to check for overflow.

MFC after: 3 weeks


# 180347 07-Jul-2008 kib

Add #include <inttypes.h> for the strtoimax().

Submitted by: Jilles Tjoelker <jilles stack nl>
MFC after: 3 days


# 173719 18-Nov-2007 jb

Constify the first argument to expand_number() so that it can
be called with a const without the compiler grisling.


# 172049 05-Sep-2007 pjd

- Fix strange for loop.

Reported by: phk

- While here, check the unit before calculating the actually number.
This way we can return EINVAL for invalid unit instead of ERANGE.

Approved by: re (kensmith)


# 172029 01-Sep-2007 pjd

Implement expand_number(3), which is the opposite of humanize_number(3), ie.
a number in human-readable form is converted to int64_t, for example:
123b -> 123
10k -> 10240
16G -> 17179869184

First version submitted by: Eric Anderson <anderson@freebsd.org>
Approved by: re (bmah)