minor KNF nits, space damage.

This commit is contained in:
mrg 1999-01-31 08:00:50 +00:00
parent 21ab415ee6
commit 69b1acad99

View File

@ -1,4 +1,4 @@
/* $NetBSD: strpct.c,v 1.2 1998/05/08 18:43:54 fair Exp $ */ /* $NetBSD: strpct.c,v 1.3 1999/01/31 08:00:50 mrg Exp $ */
/*- /*-
* Copyright (c) 1998 The NetBSD Foundation, Inc. * Copyright (c) 1998 The NetBSD Foundation, Inc.
@ -17,8 +17,8 @@
* documentation and/or other materials provided with the distribution. * documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software * 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement: * must display the following acknowledgement:
* This product includes software developed by the NetBSD * This product includes software developed by the NetBSD
* Foundation, Inc. and its contributors. * Foundation, Inc. and its contributors.
* 4. Neither the name of The NetBSD Foundation nor the names of its * 4. Neither the name of The NetBSD Foundation nor the names of its
* contributors may be used to endorse or promote products derived * contributors may be used to endorse or promote products derived
* from this software without specific prior written permission. * from this software without specific prior written permission.
@ -51,49 +51,49 @@
#include <stdio.h> #include <stdio.h>
char * strpct __P((u_long, u_long, u_int)); char *strpct __P((u_long, u_long, u_int));
char * char *
strpct(numerator, denominator, digits) strpct(numerator, denominator, digits)
u_long numerator, denominator; u_long numerator, denominator;
u_int digits; u_int digits;
{ {
int i; int i;
u_long result, factor; u_long result, factor;
static char percent[32]; static char percent[32];
/* I should check for digit overflow here, too XXX */ /* I should check for digit overflow here, too XXX */
factor = 100L; factor = 100L;
for(i = 0; i < digits; i++) { for (i = 0; i < digits; i++) {
factor *= 10; factor *= 10;
} }
/* watch out for overflow! */ /* watch out for overflow! */
if (numerator < (ULONG_MAX / factor)) { if (numerator < (ULONG_MAX / factor))
numerator *= factor; numerator *= factor;
} else { else {
/* toss some of the bits of lesser significance */ /* toss some of the bits of lesser significance */
denominator /= factor; denominator /= factor;
} }
if (denominator == 0L) if (denominator == 0L)
denominator = 1L; denominator = 1L;
result = numerator / denominator; result = numerator / denominator;
if (digits == 0) { if (digits == 0)
(void) snprintf(percent, sizeof(percent), "%lu%%", result); (void)snprintf(percent, sizeof(percent), "%lu%%", result);
} else { else {
char fmt[32]; char fmt[32];
/* indirection to produce the right output format */ /* indirection to produce the right output format */
(void) snprintf(fmt, sizeof(fmt), "%%lu.%%0%ulu%%%%", digits); (void)snprintf(fmt, sizeof(fmt), "%%lu.%%0%ulu%%%%", digits);
factor /= 100L; /* undo initialization */ factor /= 100L; /* undo initialization */
(void) snprintf(percent, sizeof(percent), (void)snprintf(percent, sizeof(percent), fmt, result / factor,
fmt, result / factor, result % factor); result % factor);
} }
return(percent); return (percent);
} }