summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Collet <cyan@fb.com>2017-05-26 21:38:47 (GMT)
committerYann Collet <cyan@fb.com>2017-05-26 21:38:47 (GMT)
commit03d8586fca653cb10379a6a4f310b0724d9ac6ac (patch)
treee7fc7d3a349a80648d157a540af70fbf1c8ff615
parent8c355d17fb72152f83f357c6ced061c078a9b34d (diff)
downloadlz4-03d8586fca653cb10379a6a4f310b0724d9ac6ac.zip
lz4-03d8586fca653cb10379a6a4f310b0724d9ac6ac.tar.gz
lz4-03d8586fca653cb10379a6a4f310b0724d9ac6ac.tar.bz2
cli accept block sizes with KB / MB prefixes
-rw-r--r--programs/lz4cli.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/programs/lz4cli.c b/programs/lz4cli.c
index 10aa5aa..f3583ef 100644
--- a/programs/lz4cli.c
+++ b/programs/lz4cli.c
@@ -258,14 +258,22 @@ static int exeNameMatch(const char* exeName, const char* test)
}
/*! readU32FromChar() :
- @return : unsigned integer value reach from input in `char` format
+ @return : unsigned integer value read from input in `char` format
+ allows and interprets K, KB, KiB, M, MB and MiB suffix.
Will also modify `*stringPtr`, advancing it to position where it stopped reading.
- Note : this function can overflow if result > MAX_UINT */
+ Note : function result can overflow if digit string > MAX_UINT */
static unsigned readU32FromChar(const char** stringPtr)
{
unsigned result = 0;
while ((**stringPtr >='0') && (**stringPtr <='9'))
result *= 10, result += **stringPtr - '0', (*stringPtr)++ ;
+ if ((**stringPtr=='K') || (**stringPtr=='M')) {
+ result <<= 10;
+ if (**stringPtr=='M') result <<= 10;
+ (*stringPtr)++ ;
+ if (**stringPtr=='i') (*stringPtr)++;
+ if (**stringPtr=='B') (*stringPtr)++;
+ }
return result;
}