Re: [PATCH v3] perf tools: New function to parse stringrepresenting size in bytes

From: Hitoshi Mitake
Date: Sun Nov 15 2009 - 05:57:34 EST


From: Ingo Molnar <mingo@xxxxxxx>
Subject: Re: [PATCH v3] perf tools: New function to parse string representing size in bytes
Date: Sun, 15 Nov 2009 11:28:59 +0100

>
> * Hitoshi Mitake <mitake@xxxxxxxxxxxxxxxxxxxxx> wrote:
>
> > + * bytesexp2int()
>
> i suspect this could be named 'bytestring2ll' ? Is 'bytesexp' an
> existing naming in other libraries?

Sorry, I've forgot to rename.
And bytesexp may not exist in other libraries.
I couldn't create nice name for the notion number + unit in byes.

>
> > + * Parse (\d+)(b|B|kb|KB|mb|MB|gb|GB|tb|TB) (e.g. "256MB")
> > + * and return its numeric value
> > + */
> > +long long int bytesexp2int(const char *str)
>
> we have type shortcuts for 'long long': s64.
Thanks, I use s64. This is easy to type.

>
> > +{
> > + unsigned int i;
> > + long long int length = -1, unit = 1;
>
> s64 too i suspect.
>
> > +tera:
> > + unit = (long long int)K * K * K * K;
>
> Note, you can probably avoid this type cast if you define the 'K'
> literal as 1024LL or so.
I've forgot this notation, thanks.

>
> > + length = atoll(str) * unit;
>
> we might want to take a naming clue here and name this new function as
> atoll_exp(), to signal that it works like atoll, just with an extension
> for KB/MB/GB/etc. expressions?

Hm, how about "atoll_byteunit()"?
This may have no ambiguity.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/