top(1): handle 0 in "digits" functions
This commit is contained in:
parent
f9c005a17f
commit
fb7b896cd8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=334941
@ -5,7 +5,6 @@
|
||||
PROG= top
|
||||
SRCS= commands.c display.c machine.c screen.c top.c \
|
||||
username.c utils.c
|
||||
CFLAGS+= -I ${.OBJDIR}
|
||||
MAN= top.1
|
||||
|
||||
.if ${COMPILER_TYPE} == "gcc"
|
||||
|
@ -124,16 +124,18 @@ itoa7(int val)
|
||||
|
||||
/*
|
||||
* digits(val) - return number of decimal digits in val. Only works for
|
||||
* positive numbers. If val <= 0 then digits(val) == 0.
|
||||
* non-negative numbers. If val <= 0 then digits(val) == 0.
|
||||
*/
|
||||
|
||||
int
|
||||
int __pure2
|
||||
digits(int val)
|
||||
{
|
||||
int cnt = 0;
|
||||
if (val == 0) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
while (val > 0)
|
||||
{
|
||||
while (val > 0) {
|
||||
cnt++;
|
||||
val /= 10;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user