summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorotto <otto@openbsd.org>2003-12-27 19:49:51 +0000
committerotto <otto@openbsd.org>2003-12-27 19:49:51 +0000
commit0aa89f93cc962e3cceaae54f27acc9303b96cc12 (patch)
tree463f089089a3b1952702250dd6cbd56ce54f5b92 /lib/libutil
parentRemove extra \n from pf_print_state(). (diff)
downloadwireguard-openbsd-0aa89f93cc962e3cceaae54f27acc9303b96cc12.tar.xz
wireguard-openbsd-0aa89f93cc962e3cceaae54f27acc9303b96cc12.zip
o Do not drop unit when printing -100
o Round negative numbers correctly o Do not print fractional valus for byte values ok ian@ henning@
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/fmt_scaled.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/lib/libutil/fmt_scaled.c b/lib/libutil/fmt_scaled.c
index 2785f9e656f..9f75b102432 100644
--- a/lib/libutil/fmt_scaled.c
+++ b/lib/libutil/fmt_scaled.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fmt_scaled.c,v 1.1 2003/05/15 01:26:26 ian Exp $ */
+/* $OpenBSD: fmt_scaled.c,v 1.2 2003/12/27 19:49:51 otto Exp $ */
/*
* Copyright (c) 2001, 2002, 2003 Ian F. Darwin. All rights reserved.
@@ -37,7 +37,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static const char ident[] = "$OpenBSD: fmt_scaled.c,v 1.1 2003/05/15 01:26:26 ian Exp $";
+static const char ident[] = "$OpenBSD: fmt_scaled.c,v 1.2 2003/12/27 19:49:51 otto Exp $";
#endif /* LIBC_SCCS and not lint */
#include <stdio.h>
@@ -233,15 +233,18 @@ fmt_scaled(long long number, char *result)
}
}
fract = (10 * fract + 512) / 1024;
- /* if the result would be >= 10, round main number up */
+ /* if the result would be >= 10, round main number */
if (fract == 10) {
- number++;
+ if (number >= 0)
+ number++;
+ else
+ number--;
fract = 0;
}
if (number == 0)
strlcpy(result, "0B", FMT_SCALED_STRSIZE);
- else if (number > 100 || number < -100)
+ else if (unit == NONE || number >= 100 || number <= -100)
(void)snprintf(result, FMT_SCALED_STRSIZE, "%lld%c",
number, scale_chars[unit]);
else