df: more compatible -P behavior
authorRalf Friedl <Ralf.Friedl@online.de>
Tue, 9 Aug 2011 02:49:27 +0000 (04:49 +0200)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 9 Aug 2011 02:49:27 +0000 (04:49 +0200)
In coreutils df, one of the effects of the option -P is to output
everything in one line. This makes it much easier for a script to parse
the output of df.
This patch adds the same behavior to busybox df.

function                                             old     new   delta
df_main                                              853     863     +10

Signed-off-by: Ralf Friedl <Ralf.Friedl@online.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
coreutils/df.c

index 846cb38addb33730b856393c6ce0da3d73db0d96..63dbd61bd2fd4d738c2728136dc496fd66873655 100644 (file)
@@ -212,7 +212,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
                        {
                                uni_stat_t uni_stat;
                                char *uni_dev = unicode_conv_to_printable(&uni_stat, device);
-                               if (uni_stat.unicode_width > 20) {
+                               if (uni_stat.unicode_width > 20 && !(opt & OPT_POSIX)) {
                                        printf("%s\n%20s", uni_dev, "");
                                } else {
                                        printf("%s%*s", uni_dev, 20 - (int)uni_stat.unicode_width, "");
@@ -220,7 +220,7 @@ int df_main(int argc UNUSED_PARAM, char **argv)
                                free(uni_dev);
                        }
 #else
-                       if (printf("\n%-20s" + 1, device) > 20)
+                       if (printf("\n%-20s" + 1, device) > 20 && !(opt & OPT_POSIX))
                                    printf("\n%-20s", "");
 #endif