get units right

This commit is contained in:
rsc 2005-12-30 18:52:20 +00:00
parent 85f595382f
commit 2214d4b6de

View file

@ -69,6 +69,8 @@ int readconfigfile(Config *cp);
void setrootfid(void);
int ipokay(uchar *ip, ushort port);
u64int unittoull(char*);
void
usage(void)
{
@ -120,10 +122,10 @@ threadmain(int argc, char **argv)
addr = EARGF(usage());
break;
case 'b':
blocksize = strtoull(EARGF(usage()), 0, 0);
blocksize = unittoull(EARGF(usage()));
break;
case 'c':
cachesize = strtoull(EARGF(usage()), 0, 0);
cachesize = unittoull(EARGF(usage()));
break;
case 'r':
srv->alwaysreject++;
@ -163,6 +165,35 @@ threadmain(int argc, char **argv)
threadexits(nil);
}
#define TWID64 ((u64int)~(u64int)0)
u64int
unittoull(char *s)
{
char *es;
u64int n;
if(s == nil)
return TWID64;
n = strtoul(s, &es, 0);
if(*es == 'k' || *es == 'K'){
n *= 1024;
es++;
}else if(*es == 'm' || *es == 'M'){
n *= 1024*1024;
es++;
}else if(*es == 'g' || *es == 'G'){
n *= 1024*1024*1024;
es++;
}else if(*es == 't' || *es == 'T'){
n *= 1024*1024;
n *= 1024*1024;
}
if(*es != '\0')
return TWID64;
return n;
}
/*
* Handles.
*