mcexec: atobytes() to convert size string to # of bytes

This commit is contained in:
Balazs Gerofi
2017-05-24 01:39:42 +09:00
parent 74c5f61fd5
commit 9f55263528

View File

@ -1276,6 +1276,33 @@ static int rlimits[] = {
char dev[64]; char dev[64];
unsigned long atobytes(char *string)
{
unsigned long mult = 1;
char *postfix;
if (!strlen(string)) {
return 0;
}
postfix = &string[strlen(string) - 1];
if (*postfix == 'k' || *postfix == 'K') {
mult = 1024;
*postfix = 0;
}
else if (*postfix == 'm' || *postfix == 'M') {
mult = 1024 * 1024;
*postfix = 0;
}
else if (*postfix == 'g' || *postfix == 'G') {
mult = 1024 * 1024 * 1024;
*postfix = 0;
}
return atol(string) * mult;
}
static struct option mcexec_options[] = { static struct option mcexec_options[] = {
{ {
.name = "disable-vdso", .name = "disable-vdso",
@ -1410,11 +1437,11 @@ int main(int argc, char **argv)
break; break;
case 'm': case 'm':
mpol_threshold = atol(optarg); mpol_threshold = atobytes(optarg);
break; break;
case 'h': case 'h':
heap_extension = atol(optarg); heap_extension = atobytes(optarg);
break; break;
case 0: /* long opt */ case 0: /* long opt */