From 841fe8e83f969d10f48b95a007577fde34fd8532 Mon Sep 17 00:00:00 2001 From: David Schultz Date: Fri, 4 Jun 2004 09:30:51 +0000 Subject: [PATCH] Convert fsbtoblk() from a macro to a function. The redundant instances of 64-bit arithmetic were costing 775 bytes, and the inlining offered no benefit. Moreover, ambiguity as to the argument types led to the introduction of a bug (see rev 1.56). Also, remove some casts that are now clearly redundant. Inspired by: 67467 --- bin/df/df.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/bin/df/df.c b/bin/df/df.c index 96022b398913..ddeb58182c70 100644 --- a/bin/df/df.c +++ b/bin/df/df.c @@ -81,6 +81,7 @@ static int int64width(int64_t); static char *makenetvfslist(void); static void prthuman(const struct statfs *, int64_t); static void prthumanval(int64_t); +static intmax_t fsbtoblk(int64_t, uint64_t, u_long); static void prtstat(struct statfs *, struct maxwidths *); static size_t regetmntinfo(struct statfs **, long, const char **); static void update_maxwidths(struct maxwidths *, const struct statfs *); @@ -345,10 +346,15 @@ prthumanval(int64_t bytes) * Convert statfs returned file system size into BLOCKSIZE units. * Attempts to avoid overflow for large file systems. */ -#define fsbtoblk(num, fsbs, bs) \ - (((fsbs) != 0 && (fsbs) < (bs)) ? \ - (num) / (intmax_t)((bs) / (fsbs)) : \ - (num) * (intmax_t)((fsbs) / (bs))) +static intmax_t +fsbtoblk(int64_t num, uint64_t fsbs, u_long bs) +{ + + if (fsbs != 0 && fsbs < bs) + return (num / (intmax_t)(bs / fsbs)); + else + return (num * (intmax_t)(fsbs / bs)); +} /* * Print out status about a file system. @@ -392,11 +398,10 @@ prtstat(struct statfs *sfsp, struct maxwidths *mwp) prthuman(sfsp, used); } else { (void)printf(" %*jd %*jd %*jd", - mwp->total, (intmax_t)fsbtoblk(sfsp->f_blocks, + mwp->total, fsbtoblk(sfsp->f_blocks, sfsp->f_bsize, blocksize), - mwp->used, (intmax_t)fsbtoblk(used, sfsp->f_bsize, - blocksize), - mwp->avail, (intmax_t)fsbtoblk(sfsp->f_bavail, + mwp->used, fsbtoblk(used, sfsp->f_bsize, blocksize), + mwp->avail, fsbtoblk(sfsp->f_bavail, sfsp->f_bsize, blocksize)); } (void)printf(" %5.0f%%",