Allow for large scale factors. C99 warrants that

ULLONG_MAX is not less than 2^64-1; and uintmax_t
cannot be more narrow than unsigned long long.
This allows for scale factors up to Exa inclusively.

Use plain int for the scale index to be consistent
with ifcmds.c and enum.
This commit is contained in:
Yaroslav Tykhiy 2006-11-27 15:26:26 +00:00
parent 41af362198
commit f5d4751c8a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=164671
2 changed files with 11 additions and 10 deletions

View File

@ -50,10 +50,10 @@ struct convtbl convtbl[] = {
static
struct convtbl *
get_tbl_ptr(const u_long size, const u_int scale)
get_tbl_ptr(const uintmax_t size, const int scale)
{
u_long tmp;
u_int idx;
uintmax_t tmp;
int idx;
/* If our index is out of range, default to auto-scaling. */
idx = scale < SC_AUTO ? scale : SC_AUTO;
@ -73,7 +73,7 @@ get_tbl_ptr(const u_long size, const u_int scale)
}
double
convert(const u_long size, const u_int scale)
convert(const uintmax_t size, const int scale)
{
struct convtbl *tp;
@ -83,7 +83,7 @@ convert(const u_long size, const u_int scale)
}
const char *
get_string(const u_long size, const u_int scale)
get_string(const uintmax_t size, const int scale)
{
struct convtbl *tp;

View File

@ -32,10 +32,11 @@
#define _CONVTBL_H_
#include <sys/types.h>
#include <stdint.h>
#define BITS (1)
#define BYTES (1)
#define KILO (1024)
#define KILO (1024LL)
#define MEGA (KILO * 1024)
#define GIGA (MEGA * 1024)
@ -55,14 +56,14 @@ enum scale {
#define BYTE (1)
struct convtbl {
u_int mul;
u_int scale;
uintmax_t mul;
uintmax_t scale;
const char *str;
};
extern struct convtbl convtbl[];
extern double convert(const u_long, const u_int);
extern const char *get_string(const u_long, const u_int);
extern double convert(const uintmax_t, const int);
extern const char *get_string(const uintmax_t, const int);
#endif /* ! _CONVTBL_H_ */