Remember to delete un-expandable variables, and do a better job of expanding
[oweals/busybox.git] / ls.c
diff --git a/ls.c b/ls.c
index 06e23e6123b4d8dfed28673848ecbbab86c11d3f..a8d7b182ff59b7279173b5a4f6e2e6c79ea48243 100644 (file)
--- a/ls.c
+++ b/ls.c
@@ -50,7 +50,6 @@ enum {
 
 /************************************************************************/
 
-#include "busybox.h"
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
@@ -58,15 +57,16 @@ enum {
 #include <dirent.h>
 #include <errno.h>
 #include <stdio.h>
-#ifdef BB_FEATURE_LS_TIMESTAMPS
-#include <time.h>
-#endif
 #include <string.h>
 #include <stdlib.h>
-
 #include <fcntl.h>
 #include <signal.h>
 #include <sys/ioctl.h>
+#include "busybox.h"
+
+#ifdef BB_FEATURE_LS_TIMESTAMPS
+#include <time.h>
+#endif
 
 #ifndef MAJOR
 #define MAJOR(dev) (((dev)>>8)&0xff)
@@ -186,7 +186,7 @@ static unsigned short column_width = COLUMN_WIDTH;
 static int status = EXIT_SUCCESS;
 
 #ifdef BB_FEATURE_HUMAN_READABLE
-unsigned long ls_disp_hr = KILOBYTE;
+unsigned long ls_disp_hr = 0;
 #endif
 
 static int my_stat(struct dnode *cur)
@@ -610,7 +610,8 @@ int list_single(struct dnode *dn)
                                break;
                        case LIST_BLOCKS:
 #ifdef BB_FEATURE_HUMAN_READABLE
-                               fprintf(stdout, "%5s ", format(dn->dstat.st_size, ls_disp_hr));
+                               fprintf(stdout, "%5s ", make_human_readable_str(dn->dstat.st_blocks>>1,
+                                                       (ls_disp_hr==TRUE)? 0: 1));
 #else
 #if _FILE_OFFSET_BITS == 64
                                printf("%4lld ", dn->dstat.st_blocks>>1);
@@ -647,12 +648,13 @@ int list_single(struct dnode *dn)
                                        printf("%4d, %3d ", (int)MAJOR(dn->dstat.st_rdev), (int)MINOR(dn->dstat.st_rdev));
                                } else {
 #ifdef BB_FEATURE_HUMAN_READABLE
-                                       fprintf(stdout, "%9s ", format(dn->dstat.st_size, ls_disp_hr));
+                                       fprintf(stdout, "%9s ", make_human_readable_str(dn->dstat.st_size,
+                                                               (ls_disp_hr==TRUE)? 0: 1));
 #else
 #if _FILE_OFFSET_BITS == 64
-                                       printf("%9lld ", dn->dstat.st_size);
+                                       printf("%9lld ", dn->dstat.st_size>>1);
 #else
-                                       printf("%9ld ", dn->dstat.st_size);
+                                       printf("%9ld ", dn->dstat.st_size>>1);
 #endif
 #endif
                                }
@@ -779,7 +781,7 @@ extern int ls_main(int argc, char **argv)
                                style_fmt = STYLE_LONG;
                                list_fmt |= LIST_LONG;
 #ifdef BB_FEATURE_HUMAN_READABLE
-                               ls_disp_hr = 1;
+                               ls_disp_hr = FALSE;
 #endif
                        break;
                        case 'n': list_fmt |= LIST_ID_NUMERIC; break;
@@ -826,11 +828,9 @@ extern int ls_main(int argc, char **argv)
                        case 'w': terminal_width= atoi(optarg); break;
 #endif
 #ifdef BB_FEATURE_HUMAN_READABLE
-                       case 'h': ls_disp_hr = 0; break;
-                       case 'k': ls_disp_hr = KILOBYTE; break;
-#else
-                       case 'k': break;
+                       case 'h': ls_disp_hr = TRUE; break;
 #endif
+                       case 'k': break;
                        default:
                                goto print_usage_message;
                }