Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Fix human_number is pkg_printf not being architecture consistent
Baptiste Daroussin committed 12 years ago
commit e4a237f820a0ca001cc39af2fb63a6e43071cd72
parent deafede
1 file changed +7 -22
modified libpkg/pkg_printf.c
@@ -1928,13 +1928,12 @@ gen_format(char *buf, size_t buflen, unsigned flags, const char *tail)
struct sbuf *
human_number(struct sbuf *sbuf, int64_t number, struct percent_esc *p)
{
-
	double		 num;
+
	int64_t		 num;
	int		 sign;
-
	int		 width;
	int		 scale_width;
	int		 divisor;
+
	int		 width;
	int		 scale;
-
	int		 precision;
	bool		 bin_scale;

#define MAXSCALE	7
@@ -1949,7 +1948,7 @@ human_number(struct sbuf *sbuf, int64_t number, struct percent_esc *p)

	p->flags &= ~(PP_ALTERNATE_FORM1|PP_ALTERNATE_FORM2);

-
	if (gen_format(format, sizeof(format), p->flags, ".*f") == NULL)
+
	if (gen_format(format, sizeof(format), p->flags, PRId64) == NULL)
		return (NULL);

	if (number >= 0) {
@@ -1982,26 +1981,12 @@ human_number(struct sbuf *sbuf, int64_t number, struct percent_esc *p)
	else
		width = p->width - scale_width;

-
	if (num >= 100)
-
		precision = 0;
-
	else if (num >= 10) {
-
		if (width == 0 || width > 3)
-
			precision = 1;
-
		else
-
			precision = 0;
-
	} else {
-
		if (width == 0 || width > 3)
-
			precision = 2;
-
		else if (width == 3)
-
			precision = 1;
-
		else
-
			precision = 0;
-
	}
-

-
	sbuf_printf(sbuf, format, width, num * sign, precision);
+
	sbuf_printf(sbuf, format, width, num * sign);
+
	if (number % num != 0)
+
		sbuf_printf(sbuf, ".%"PRId64, number % num);

	if (scale > 0)
-
		sbuf_printf(sbuf, "%s", 
+
		sbuf_printf(sbuf, "%s",
		    bin_scale ? bin_pfx[scale] : si_pfx[scale]);

	return (sbuf);