diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2003-08-06 19:09:10 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2003-08-06 19:09:10 +0000 |
commit | d92a7531e29e5c40b09b72f2ed1bf69182cce1e2 (patch) | |
tree | dd030c7f4f25dab76dd28b01077b773eeee38057 /bin/ls/print.c | |
parent | fb87035a8dfc1d956ee9b28618912110c4a5b4ed (diff) |
-h, human readable sizes. from a jonathon gray mail to tech@
ok ian@ millert@
Diffstat (limited to 'bin/ls/print.c')
-rw-r--r-- | bin/ls/print.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/bin/ls/print.c b/bin/ls/print.c index 90b65f751a8..30a05eaf6e9 100644 --- a/bin/ls/print.c +++ b/bin/ls/print.c @@ -1,4 +1,4 @@ -/* $OpenBSD: print.c,v 1.19 2003/06/11 23:42:12 deraadt Exp $ */ +/* $OpenBSD: print.c,v 1.20 2003/08/06 19:09:09 tedu Exp $ */ /* $NetBSD: print.c,v 1.15 1996/12/11 03:25:39 thorpej Exp $ */ /* @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)print.c 8.5 (Berkeley) 7/28/94"; #else -static char rcsid[] = "$OpenBSD: print.c,v 1.19 2003/06/11 23:42:12 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: print.c,v 1.20 2003/08/06 19:09:09 tedu Exp $"; #endif #endif /* not lint */ @@ -55,12 +55,14 @@ static char rcsid[] = "$OpenBSD: print.c,v 1.19 2003/06/11 23:42:12 deraadt Exp #include <time.h> #include <tzfile.h> #include <unistd.h> +#include <util.h> #include "ls.h" #include "extern.h" static int printaname(FTSENT *, u_long, u_long); static void printlink(FTSENT *); +static void printsize(size_t, off_t); static void printtime(time_t); static int printtype(u_int); static int compute_columns(DISPLAY *, int *); @@ -114,7 +116,7 @@ printlong(DISPLAY *dp) (void)printf("%*s%*qd ", 8 - dp->s_size, "", dp->s_size, sp->st_size); else - (void)printf("%*qd ", dp->s_size, sp->st_size); + printsize(dp->s_size, sp->st_size); if (f_accesstime) printtime(sp->st_atime); else if (f_statustime) @@ -363,3 +365,15 @@ printlink(FTSENT *p) (void)printf(" -> "); (void)putname(path); } + +static void +printsize(size_t width, off_t bytes) +{ + char ret[FMT_SCALED_STRSIZE]; + + if ((f_humanval) && (fmt_scaled(bytes, ret) != -1)) { + (void)printf("%*s ", (u_int)width, ret); + return; + } + (void)printf("%*qd ", (u_int)width, bytes); +} |