Merge branch '2580_file_size_column'
* 2580_file_size_column: (size_trunc): added ability to show size in [G|g]bytes. (size_trunc_len): process full range of uintmax_t type. Ticket #2580: file size column is bogus for widths above 9.
Этот коммит содержится в:
Коммит
8353224997
16
configure.ac
16
configure.ac
@ -193,26 +193,28 @@ AC_DEFINE(IS_AIX, 1, [Define if compiling for AIX])
|
||||
AC_MSG_RESULT(yes)
|
||||
], [AC_MSG_RESULT(no)])
|
||||
|
||||
dnl
|
||||
dnl This is from GNU fileutils, check aclocal.m4 for more information
|
||||
dnl
|
||||
AC_GET_FS_INFO
|
||||
|
||||
dnl
|
||||
dnl Missing typedefs and replacements
|
||||
dnl
|
||||
|
||||
AC_CHECK_SIZEOF(long)
|
||||
AC_CHECK_SIZEOF(long long)
|
||||
AC_TYPE_MODE_T
|
||||
AC_TYPE_UINTMAX_T
|
||||
AC_CHECK_SIZEOF(uintmax_t)
|
||||
AC_TYPE_OFF_T
|
||||
AC_CHECK_SIZEOF(off_t)
|
||||
AC_TYPE_MODE_T
|
||||
AC_TYPE_PID_T
|
||||
AC_TYPE_UID_T
|
||||
|
||||
AC_FUNC_ALLOCA
|
||||
AC_FUNC_STRCOLL
|
||||
|
||||
dnl
|
||||
dnl This is from GNU fileutils, check aclocal.m4 for more information
|
||||
dnl uintmat_t is required for FS info
|
||||
dnl
|
||||
AC_GET_FS_INFO
|
||||
|
||||
dnl
|
||||
dnl X11 support.
|
||||
dnl Used to read keyboard modifiers when running under X11.
|
||||
|
49
lib/util.c
49
lib/util.c
@ -332,10 +332,17 @@ size_trunc (uintmax_t size, gboolean use_si)
|
||||
{
|
||||
divisor = use_si ? 1000 : 1024;
|
||||
xtra = use_si ? "k" : "K";
|
||||
|
||||
if (size / divisor > 999999999UL)
|
||||
{
|
||||
divisor = use_si ? (1000 * 1000) : (1024 * 1024);
|
||||
xtra = use_si ? "m" : "M";
|
||||
|
||||
if (size / divisor > 999999999UL)
|
||||
{
|
||||
divisor = use_si ? (1000 * 1000 * 1000) : (1024 * 1024 * 1024);
|
||||
xtra = use_si ? "g" : "G";
|
||||
}
|
||||
}
|
||||
}
|
||||
g_snprintf (x, sizeof (x), "%.0f%s", 1.0 * size / divisor, xtra);
|
||||
@ -389,7 +396,36 @@ size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gbool
|
||||
{
|
||||
/* Avoid taking power for every file. */
|
||||
static const uintmax_t power10[] = {
|
||||
1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000
|
||||
/* we hope that size of uintmax_t is 4 bytes at least */
|
||||
1ULL,
|
||||
10ULL,
|
||||
100ULL,
|
||||
1000ULL,
|
||||
10000ULL,
|
||||
100000ULL,
|
||||
1000000ULL,
|
||||
10000000ULL,
|
||||
100000000ULL,
|
||||
1000000000ULL
|
||||
/* maximmum value of uintmax_t (in case of 4 bytes) is
|
||||
4294967295
|
||||
*/
|
||||
#if SIZEOF_UINTMAX_T == 8
|
||||
,
|
||||
10000000000ULL,
|
||||
100000000000ULL,
|
||||
1000000000000ULL,
|
||||
10000000000000ULL,
|
||||
100000000000000ULL,
|
||||
1000000000000000ULL,
|
||||
10000000000000000ULL,
|
||||
100000000000000000ULL,
|
||||
1000000000000000000ULL,
|
||||
10000000000000000000ULL
|
||||
/* maximmum value of uintmax_t (in case of 8 bytes) is
|
||||
18447644073710439615
|
||||
*/
|
||||
#endif
|
||||
};
|
||||
static const char *const suffix[] = { "", "K", "M", "G", "T", "P", "E", "Z", "Y", NULL };
|
||||
static const char *const suffix_lc[] = { "", "k", "m", "g", "t", "p", "e", "z", "y", NULL };
|
||||
@ -398,6 +434,15 @@ size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gbool
|
||||
|
||||
if (len == 0)
|
||||
len = 9;
|
||||
#if SIZEOF_UINTMAX_T == 8
|
||||
/* 20 decimal digits are required to represent 8 bytes */
|
||||
else if (len > 19)
|
||||
len = 19;
|
||||
#else
|
||||
/* 10 decimal digits are required to represent 4 bytes */
|
||||
else if (len > 9)
|
||||
len = 9;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* recalculate from 1024 base to 1000 base if units>0
|
||||
@ -430,7 +475,7 @@ size_trunc_len (char *buffer, unsigned int len, uintmax_t size, int units, gbool
|
||||
break;
|
||||
}
|
||||
|
||||
if (size < power10[len - (j > 0)])
|
||||
if (size < power10[len - (j > 0 ? 1 : 0)])
|
||||
{
|
||||
g_snprintf (buffer, len + 1, "%" PRIuMAX "%s", size, use_si ? suffix_lc[j] : suffix[j]);
|
||||
break;
|
||||
|
Загрузка…
x
Ссылка в новой задаче
Block a user