| To: | xfs@xxxxxxxxxxx |
|---|---|
| Subject: | [PATCH 3/3] xfsprogs: xfs_quota: improve calculation for percentage display |
| From: | Alex Elder <aelder@xxxxxxx> |
| Date: | Wed, 24 Aug 2011 16:53:43 -0500 |
| Cc: | Alex Elder <aelder@xxxxxxx> |
| In-reply-to: | <1314222823-24101-1-git-send-email-aelder@xxxxxxx> |
| In-reply-to: | <adcfe5e08d1c060ea95a8aa43e1abade24957dd0.1314222483.git.aelder@xxxxxxx> |
| References: | <1314222823-24101-1-git-send-email-aelder@xxxxxxx> |
| References: | <adcfe5e08d1c060ea95a8aa43e1abade24957dd0.1314222483.git.aelder@xxxxxxx> |
The pct_to_string() function determines the percentage it produces
in a strange way. Simplify the function, and make it return the
simple rounded percentage value. Handle the case of an error
return from snprintf() as well.
Signed-off-by: Alex Elder <aelder@xxxxxxx>
---
quota/util.c | 20 ++++++++++----------
1 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/quota/util.c b/quota/util.c
index 18ccae2..179aafd 100644
--- a/quota/util.c
+++ b/quota/util.c
@@ -172,18 +172,18 @@ num_to_string(
char *
pct_to_string(
- __uint64_t v,
- __uint64_t t,
- char *sp,
+ __uint64_t portion,
+ __uint64_t whole,
+ char *buf,
uint size)
{
- if (t == 0 || v == 0)
- snprintf(sp, size, "%3u", (uint)0);
- else if (t == v)
- snprintf(sp, size, "%3u", (uint)100);
- else
- snprintf(sp, size, "%3u", (uint)(((double)v / t) * 100 + 1));
- return sp;
+ uint percent;
+
+ percent = whole ? (uint) (100.0 * portion / whole + 0.5) : 0;
+ if (snprintf(buf, size, "%3u", percent) < 0)
+ return "???";
+
+ return buf;
}
char *
--
1.7.6
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| ||
| Previous by Date: | Re: [GIT PULL] XFS update for 3.1-rc4, Dave Chinner |
|---|---|
| Next by Date: | [PATCH 0/3] xfsprogs: xfs_quota: a few fixes, Alex Elder |
| Previous by Thread: | [PATCH 1/3] xfsprogs: xfs_quota: return real-time used data as intended, Alex Elder |
| Next by Thread: | Re: [PATCH 3/3] xfsprogs: xfs_quota: improve calculation for percentage display, Christoph Hellwig |
| Indexes: | [Date] [Thread] [Top] [All Lists] |