summaryrefslogtreecommitdiffstats
path: root/sbin/sysctl
diff options
context:
space:
mode:
authornjl <njl@FreeBSD.org>2006-08-04 07:31:55 +0000
committernjl <njl@FreeBSD.org>2006-08-04 07:31:55 +0000
commit844254bd878791840f6bef7e7b420497eedadf07 (patch)
tree2d78a3f224f5e4d20f3e6e49a45c9e3a7dd05bd9 /sbin/sysctl
parent558c5767400d2aad6f4787b94f487d2f5fd7d22d (diff)
downloadFreeBSD-src-844254bd878791840f6bef7e7b420497eedadf07.zip
FreeBSD-src-844254bd878791840f6bef7e7b420497eedadf07.tar.gz
Use floating point instead of hacking something together. Suggested by
bde@. Fix nearby int conversion and a couple style bugs. MFC after: 1 day
Diffstat (limited to 'sbin/sysctl')
-rw-r--r--sbin/sysctl/sysctl.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c
index a1ef11c..09569c5 100644
--- a/sbin/sysctl/sysctl.c
+++ b/sbin/sysctl/sysctl.c
@@ -577,15 +577,14 @@ show_var(int *oid, int nlen)
val = "";
while (len >= sizeof(int)) {
fputs(val, stdout);
- if(*fmt == 'U')
+ if (*fmt == 'U')
printf(hflag ? "%'u" : "%u", *(unsigned int *)p);
else if (*fmt == 'K') {
- if (*(int *)p < 0)
- printf("%d", *(int *)p);
+ if (*(long *)p < 0)
+ printf("%ld", *(long *)p);
else
- printf("%d.%dC",
- (*(int *)p - 2732) / 10,
- abs((*(int *)p - 2732) % 10));
+ printf("%.1fC",
+ (*(long *)p - 2732.0) / 10);
} else
printf(hflag ? "%'d" : "%d", *(int *)p);
val = " ";
@@ -601,15 +600,14 @@ show_var(int *oid, int nlen)
val = "";
while (len >= sizeof(long)) {
fputs(val, stdout);
- if(*fmt == 'U')
+ if (*fmt == 'U')
printf(hflag ? "%'lu" : "%lu", *(unsigned long *)p);
else if (*fmt == 'K') {
if (*(long *)p < 0)
printf("%ld", *(long *)p);
else
- printf("%ld.%ldC",
- (*(long *)p - 2732) / 10,
- abs((*(long *)p - 2732) % 10));
+ printf("%.1fC",
+ (*(long *)p - 2732.0) / 10);
} else
printf(hflag ? "%'ld" : "%ld", *(long *)p);
val = " ";
OpenPOWER on IntegriCloud