Mirror of git://git.busybox.net/busybox with our patches on top
Source
xxxxxxxxxx
/* coreutils also understands TPEZY suffixes for tera- and so on, with B suffix for decimal */
/* vi: set sw=4 ts=4: */
/*
* ascii-to-numbers implementations for busybox
*
* Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org>
*
* Licensed under GPLv2, see file LICENSE in this source tree.
*/
static ALWAYS_INLINE
unsigned bb_strtoui(const char *str, char **end, int b)
{
unsigned long v = strtoul(str, end, b);
if (v > UINT_MAX) {
errno = ERANGE;
return UINT_MAX;
}
return v;
}
/* libc has no strtoui, so we need to create/use our own */
/* A few special cases */
int FAST_FUNC xatoi_positive(const char *numstr)
{
return xatou_range(numstr, 0, INT_MAX);
}
uint16_t FAST_FUNC xatou16(const char *numstr)
{
return xatou_range(numstr, 0, 0xffff);
}
const struct suffix_mult bkm_suffixes[] = {
{ "b", 512 },
{ "k", 1024 },
{ "m", 1024*1024 },
{ "", 0 }
};
const struct suffix_mult cwbkMG_suffixes[] = {
{ "c", 1 },
{ "w", 2 },
{ "b", 512 },
{ "kB", 1000 },
{ "kD", 1000 },
{ "k", 1024 },
{ "KB", 1000 }, /* compat with coreutils dd */
{ "KD", 1000 }, /* compat with coreutils dd */
{ "K", 1024 }, /* compat with coreutils dd */
{ "MB", 1000000 },
{ "MD", 1000000 },
{ "M", 1024*1024 },
{ "GB", 1000000000 },
{ "GD", 1000000000 },