Merge pull request #301 from pcarrier/pierre/gsize

src/jnienv.cpp: support G size suffix
This commit is contained in:
Joel Dice 2014-07-22 08:34:26 -06:00
commit e662d5c9cf

View File

@ -3286,19 +3286,30 @@ int parseSize(const char* s)
{
unsigned length = strlen(s);
RUNTIME_ARRAY(char, buffer, length + 1);
if (length == 0) {
if (length == 0)
return 0;
} else if (s[length - 1] == 'k' or s[length - 1] == 'K') {
char suffix = s[length - 1];
if (suffix== 'k' or suffix == 'K') {
memcpy(RUNTIME_ARRAY_BODY(buffer), s, length - 1);
RUNTIME_ARRAY_BODY(buffer)[length - 1] = 0;
return atoi(RUNTIME_ARRAY_BODY(buffer)) * 1024;
} else if (s[length - 1] == 'm' or s[length - 1] == 'M') {
}
if (suffix == 'm' or suffix == 'M') {
memcpy(RUNTIME_ARRAY_BODY(buffer), s, length - 1);
RUNTIME_ARRAY_BODY(buffer)[length - 1] = 0;
return atoi(RUNTIME_ARRAY_BODY(buffer)) * 1024 * 1024;
} else {
return atoi(s);
}
if (suffix == 'g' or suffix == 'G') {
memcpy(RUNTIME_ARRAY_BODY(buffer), s, length - 1);
RUNTIME_ARRAY_BODY(buffer)[length - 1] = 0;
return atoi(RUNTIME_ARRAY_BODY(buffer)) * 1024 * 1024 * 1024;
}
return atoi(s);
}
void append(char** p, const char* value, unsigned length, char tail)