public inbox for netdev@vger.kernel.org 
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber•org>
To: Petr Machata <me@pmachata•org>
Cc: netdev@vger•kernel.org, dsahern@gmail•com, Po.Liu@nxp•com,
	toke@toke•dk, dave.taht@gmail•com, edumazet@google•com,
	tahiliani@nitk•edu.in, vtlam@google•com, leon@kernel•org
Subject: Re: [PATCH iproute2-next 3/6] lib: Move sprint_size() from tc here, add print_size()
Date: Mon, 30 Nov 2020 16:39:04 -0800	[thread overview]
Message-ID: <20201130163904.14110c5c@hermes.local> (raw)
In-Reply-To: <96d90dc75f2c1676b03a119307f068d818b35798.1606774951.git.me@pmachata.org>

On Mon, 30 Nov 2020 23:59:39 +0100
Petr Machata <me@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	other threads:[~2020-12-01  0:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-30 22:59 [PATCH iproute2-next 0/6] Move rate and size parsing and output to lib Petr Machata
2020-11-30 22:59 ` [PATCH iproute2-next 1/6] Move the use_iec declaration to the tools Petr Machata
2020-11-30 22:59 ` [PATCH iproute2-next 2/6] lib: Move print_rate() from tc here; modernize Petr Machata
2020-12-01  0:35   ` Stephen Hemminger
2020-12-01 22:56     ` Petr Machata
2020-11-30 22:59 ` [PATCH iproute2-next 3/6] lib: Move sprint_size() from tc here, add print_size() Petr Machata
2020-12-01  0:39   ` Stephen Hemminger [this message]
2020-12-01 22:41     ` Petr Machata
2020-12-02  4:07       ` David Ahern
2020-11-30 22:59 ` [PATCH iproute2-next 4/6] lib: Move get_rate(), get_rate64() from tc here Petr Machata
2020-11-30 22:59 ` [PATCH iproute2-next 5/6] lib: Move get_size() " Petr Machata
2020-11-30 22:59 ` [PATCH iproute2-next 6/6] lib: print_rate(): Fix formatting small rates in IEC mode Petr Machata

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201130163904.14110c5c@hermes.local \
    --to=stephen@networkplumber$(echo .)org \
    --cc=Po.Liu@nxp$(echo .)com \
    --cc=dave.taht@gmail$(echo .)com \
    --cc=dsahern@gmail$(echo .)com \
    --cc=edumazet@google$(echo .)com \
    --cc=leon@kernel$(echo .)org \
    --cc=me@pmachata$(echo .)org \
    --cc=netdev@vger$(echo .)kernel.org \
    --cc=tahiliani@nitk$(echo .)edu.in \
    --cc=toke@toke$(echo .)dk \
    --cc=vtlam@google$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox