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:
parent
41af362198
commit
f5d4751c8a
@ -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;
|
||||
|
||||
|
@ -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_ */
|
||||
|
Loading…
Reference in New Issue
Block a user