[PATCH 3/3] xfsprogs: xfs_quota: improve calculation for percentage display

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

_______________________________________________
xfs mailing list
xfs@xxxxxxxxxxx
http://oss.sgi.com/mailman/listinfo/xfs


[Index of Archives]     [Linux XFS Devel]     [Linux Filesystem Development]     [Filesystem Testing]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux