Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
humanize_number: sync from libutil
Baptiste Daroussin committed 2 years ago
commit 078651fb814b095f88a1a7199b330024c42d80ed
parent 210e422
1 file changed +7 -4
modified compat/humanize_number.c
@@ -1,6 +1,8 @@
/*	$NetBSD: humanize_number.c,v 1.14 2008/04/28 20:22:59 martin Exp $	*/

-
/*
+
/*-
+
 * SPDX-License-Identifier: BSD-2-Clause
+
 *
 * Copyright (c) 1997, 1998, 1999, 2002 The NetBSD Foundation, Inc.
 * Copyright 2013 John-Mark Gurney <jmg@FreeBSD.org>
 * All rights reserved.
@@ -45,7 +47,7 @@

#include "humanize_number.h"

-
static const int maxscale = 7;
+
static const int maxscale = 6;

int
humanize_number(char *buf, size_t len, int64_t quotient,
@@ -66,7 +68,7 @@ humanize_number(char *buf, size_t len, int64_t quotient,
		return (-1);
	if (scale < 0)
		return (-1);
-
	else if (scale >= maxscale &&
+
	else if (scale > maxscale &&
	    ((scale & ~(HN_AUTOSCALE|HN_GETSCALE)) != 0))
		return (-1);
	if ((flags & HN_DIVISOR_1000) && (flags & HN_IEC_PREFIXES))
@@ -145,7 +147,8 @@ humanize_number(char *buf, size_t len, int64_t quotient,
		 */
		for (i = 0;
		    (quotient >= max || (quotient == max - 1 &&
-
		    remainder >= divisordeccut)) && i < maxscale; i++) {
+
		    (remainder >= divisordeccut || remainder >=
+
		    divisor / 2))) && i < maxscale; i++) {
			remainder = quotient % divisor;
			quotient /= divisor;
		}