On Mon, 30 Nov 2020 23:59:39 +0100
Petr Machata <m...@pmachata.org> wrote:

> +char *sprint_size(__u32 sz, char *buf)
> +{
> +     size_t len = SPRINT_BSIZE - 1;
> +     double tmp = sz;
> +
> +     if (sz >= 1024*1024 && fabs(1024*1024*rint(tmp/(1024*1024)) - sz) < 
> 1024)
> +             snprintf(buf, len, "%gMb", rint(tmp/(1024*1024)));
> +     else if (sz >= 1024 && fabs(1024*rint(tmp/1024) - sz) < 16)
> +             snprintf(buf, len, "%gKb", rint(tmp/1024));
> +     else
> +             snprintf(buf, len, "%ub", sz);
> +
> +     return buf;
> +}

Add some whitespace here and maybe some constants like mb and kb?

Also, instead of magic SPRINT_BSIZE, why not take a len param (and name it 
snprint_size)?

Yes when you copy/paste code it is good time to get it back to current style
standards.

Reply via email to