diff options
author | joerg <joerg@FreeBSD.org> | 1997-03-23 18:53:01 +0000 |
---|---|---|
committer | joerg <joerg@FreeBSD.org> | 1997-03-23 18:53:01 +0000 |
commit | e571e75266c1a75ac309339c04879886cbd298cf (patch) | |
tree | cdf253c6d6aff1974ea3a063441dd6a97ab2b038 /contrib/top/utils.c | |
parent | c1a738a3bedc8182878c8f04311d72237fc15d4b (diff) | |
download | FreeBSD-src-e571e75266c1a75ac309339c04879886cbd298cf.zip FreeBSD-src-e571e75266c1a75ac309339c04879886cbd298cf.tar.gz |
Apply the FreeBSD-local patches.
Obtained from: The ports collection.
Diffstat (limited to 'contrib/top/utils.c')
-rw-r--r-- | contrib/top/utils.c | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/contrib/top/utils.c b/contrib/top/utils.c index 67b64e9..e136d2a 100644 --- a/contrib/top/utils.c +++ b/contrib/top/utils.c @@ -308,9 +308,13 @@ long *diffs; /* calculate percentages based on overall change, rounding up */ half_total = total_change / 2l; - for (i = 0; i < cnt; i++) - { - *out++ = (int)((*diffs++ * 1000 + half_total) / total_change); + + /* Do not divide by 0. Causes Floating point exception */ + if(total_change) { + for (i = 0; i < cnt; i++) + { + *out++ = (int)((*diffs++ * 1000 + half_total) / total_change); + } } /* return the total in case the caller wants to use it */ @@ -329,9 +333,6 @@ long *diffs; /* externs referenced by errmsg */ -extern char *sys_errlist[]; -extern int sys_nerr; - char *errmsg(errnum) int errnum; @@ -339,7 +340,7 @@ int errnum; { if (errnum > 0 && errnum < sys_nerr) { - return(sys_errlist[errnum]); + return((char *)sys_errlist[errnum]); } return("No error"); } @@ -451,3 +452,35 @@ int amt; return(ret); } + +char *format_k2(amt) + +int amt; + +{ + static char retarray[NUM_STRINGS][16]; + static int index = 0; + register char *p; + register char *ret; + register char tag = 'K'; + + p = ret = retarray[index]; + index = (index + 1) % NUM_STRINGS; + + if (amt >= 100000) + { + amt = (amt + 512) / 1024; + tag = 'M'; + if (amt >= 100000) + { + amt = (amt + 512) / 1024; + tag = 'G'; + } + } + + p = strecpy(p, itoa(amt)); + *p++ = tag; + *p = '\0'; + + return(ret); +} |