diff options
author | das <das@FreeBSD.org> | 2004-06-04 09:30:51 +0000 |
---|---|---|
committer | das <das@FreeBSD.org> | 2004-06-04 09:30:51 +0000 |
commit | 08c3b6bf168300e2c76971c27e8997b3384a3a2d (patch) | |
tree | 3b6fbb98420ad81905b99f647899b0290c901b1e /bin | |
parent | 9bb2c2f2d29e403661d3a82df654de61b0356def (diff) | |
download | FreeBSD-src-08c3b6bf168300e2c76971c27e8997b3384a3a2d.zip FreeBSD-src-08c3b6bf168300e2c76971c27e8997b3384a3a2d.tar.gz |
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
Diffstat (limited to 'bin')
-rw-r--r-- | bin/df/df.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/bin/df/df.c b/bin/df/df.c index 96022b3..ddeb581 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%%", |