* util.c (size_trunc_len): Add units parameter. Change all

callers.
This commit is contained in:
Pavel Roskin 2001-08-30 16:41:08 +00:00
parent 242a26c03b
commit 1ef25591d2
4 changed files with 11 additions and 5 deletions

View File

@ -1,5 +1,8 @@
2001-08-30 David Martin <dmartina@excite.es>
* util.c (size_trunc_len): Add units parameter. Change all
callers.
* util.c (size_trunc_len): Print size values with some (little)
sense for tiny and even wee lengths (i.e. squeezed X terminals).

View File

@ -206,7 +206,7 @@ string_file_size (file_entry *fe, int len)
else
#endif
{
size_trunc_len (buffer, len, fe->buf.st_size);
size_trunc_len (buffer, len, fe->buf.st_size, 0);
}
return buffer;
}

View File

@ -311,9 +311,12 @@ char *size_trunc_sep (double size)
* not including trailing 0. BUFFER should be at least LEN+1 long.
* This function is called for every file on panels, so avoid
* floating point by any means.
*
* Units: size units (filesystem sizes are 1K blocks)
* 0=bytes, 1=Kbytes, 2=Mbytes, etc.
*/
void
size_trunc_len (char *buffer, int len, off_t size)
size_trunc_len (char *buffer, int len, off_t size, int units)
{
/* Avoid taking power for every file. */
static const off_t power10 [] =
@ -327,9 +330,9 @@ size_trunc_len (char *buffer, int len, off_t size)
if (len == 0 || len > 9)
len = 9;
for (j = 0; suffix [j] != NULL; j++) {
for (j = units; suffix [j] != NULL; j++) {
if (size == 0) {
if (j == 0) {
if (j == units) {
/* Empty files will print "0" even with minimal width. */
g_snprintf (buffer, len + 1, "0");
break;

View File

@ -18,7 +18,7 @@ char *fake_name_quote (const char *c, int quote_percent);
char *name_trunc (char *txt, int trunc_len);
char *size_trunc (double size);
char *size_trunc_sep (double size);
void size_trunc_len (char *buffer, int len, off_t size);
void size_trunc_len (char *buffer, int len, off_t size, int units);
int is_exe (mode_t mode);
char *string_perm (mode_t mode_bits);
char *strip_password (char *path, int has_prefix);