(size_trunc_len): support automatic maximum unit for specified size.
Fix typos. Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
Этот коммит содержится в:
родитель
22f0cac4ea
Коммит
ef94b84eaf
15
lib/util.c
15
lib/util.c
@ -406,6 +406,7 @@ size_trunc_sep (uintmax_t size, gboolean use_si)
|
||||
*
|
||||
* Units: size units (filesystem sizes are 1K blocks)
|
||||
* 0=bytes, 1=Kbytes, 2=Mbytes, etc.
|
||||
* -1 means maximum possible unit for specified size
|
||||
*/
|
||||
|
||||
void
|
||||
@ -425,7 +426,7 @@ size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gbool
|
||||
10000000ULL,
|
||||
100000000ULL,
|
||||
1000000000ULL
|
||||
/* maximmum value of uintmax_t (in case of 4 bytes) is
|
||||
/* maximum value of uintmax_t (in case of 4 bytes) is
|
||||
4294967295
|
||||
*/
|
||||
#if SIZEOF_UINTMAX_T == 8
|
||||
@ -440,7 +441,7 @@ size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gbool
|
||||
100000000000000000ULL,
|
||||
1000000000000000000ULL,
|
||||
10000000000000000000ULL
|
||||
/* maximmum value of uintmax_t (in case of 8 bytes) is
|
||||
/* maximum value of uintmax_t (in case of 8 bytes) is
|
||||
18447644073710439615
|
||||
*/
|
||||
#endif
|
||||
@ -462,6 +463,16 @@ size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gbool
|
||||
len = 9;
|
||||
#endif
|
||||
|
||||
/* find maximum unit */
|
||||
if (units < 0)
|
||||
{
|
||||
const unsigned int divider = use_si ? 1000 : 1024;
|
||||
uintmax_t size_remain = size;
|
||||
|
||||
for (units = 0; size_remain >= divider; units++)
|
||||
size_remain /= divider;
|
||||
}
|
||||
|
||||
/*
|
||||
* recalculate from 1024 base to 1000 base if units>0
|
||||
* We can't just multiply by 1024 - that might cause overflow
|
||||
|
Загрузка…
Ссылка в новой задаче
Block a user