Extract parse_size function from ramdisk command.
Change-Id: If7dd36321e1ed2feb20b4c76ddaf303bc997d8b7 Reviewed-on: https://review.haiku-os.org/c/1018 Reviewed-by: Jérôme Duval <[email protected]> Reviewed-by: Axel Dörfler <[email protected]>
This commit is contained in:
committed by
Axel Dörfler
parent
0ca56bdecd
commit
7232789211
+2
-23
@@ -17,6 +17,7 @@
|
||||
#include <String.h>
|
||||
|
||||
#include <AutoDeleter.h>
|
||||
#include <StringForSize.h>
|
||||
#include <TextTable.h>
|
||||
|
||||
#include <file_systems/ram_disk/ram_disk.h>
|
||||
@@ -140,29 +141,7 @@ command_register(int argc, const char* const* argv)
|
||||
case 's':
|
||||
{
|
||||
const char* sizeString = optarg;
|
||||
char* end;
|
||||
deviceSize = strtoll(sizeString, &end, 0);
|
||||
if (end != sizeString && deviceSize > 0) {
|
||||
int64 originalDeviceSize = deviceSize;
|
||||
switch (*end) {
|
||||
case 'g':
|
||||
deviceSize *= 1024;
|
||||
case 'm':
|
||||
deviceSize *= 1024;
|
||||
case 'k':
|
||||
deviceSize *= 1024;
|
||||
end++;
|
||||
break;
|
||||
case '\0':
|
||||
break;
|
||||
default:
|
||||
deviceSize = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
if (deviceSize > 0 && originalDeviceSize > deviceSize)
|
||||
deviceSize = -1;
|
||||
}
|
||||
deviceSize = parse_size(sizeString);
|
||||
|
||||
if (deviceSize <= 0) {
|
||||
fprintf(stderr, "Error: Invalid size argument: \"%s\"\n",
|
||||
|
||||
Reference in New Issue
Block a user