Here is the FreeBSD commit [1].

Aside from FreeBSD compatibility, I also think it makes sense because
'du' has had -c corresponding to the long option --total since very
early Fileutils releases. It is in the fileutils-3.13 tarball, but
has no mention in NEWS. :'(

[1] 
https://github.com/freebsd/freebsd-src/commit/076419d2073e67d516cb96f8b837ac6cfa754624

-- 8<--

The --total option to 'df' was added in coreutils-7.0 (2008). FreeBSD
5.3.0 (2004) had the -c option for the same purpose. This long option
previously had no short option, so this patch adds -c to be compatible
with FreeBSD.

* NEWS: Mention the new short option.
* doc/coreutils.texi (df invocation): Document the short option.
* src/df.c (TOTAL_OPTION): Remove definition.
(long_options, usage, main): Add the short option.
* tests/df/total-verify.sh: Test the short option.
---
 NEWS                     |  3 +++
 doc/coreutils.texi       |  4 +++-
 src/df.c                 |  9 ++++-----
 tests/df/total-verify.sh | 20 +++++++++++---------
 4 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/NEWS b/NEWS
index 2319e4517..ad7d48f33 100644
--- a/NEWS
+++ b/NEWS
@@ -33,6 +33,9 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   'tail' now accepts the --debug option, which is currently used to
   detail the --follow implementation being used.
 
+  'df' now supports the short option -c corresponding to the existing long
+  option --total, for compatibility with FreeBSD.
+
   'du' now supports the short option -A corresponding to the existing long
   option --apparent-size, for compatibility with FreeBSD.
 
diff --git a/doc/coreutils.texi b/doc/coreutils.texi
index 583686212..1be93ed7d 100644
--- a/doc/coreutils.texi
+++ b/doc/coreutils.texi
@@ -12617,7 +12617,9 @@ @node df invocation
 but in general this option makes @command{df} much slower, especially when
 there are many or very busy file systems.
 
-@item --total
+@item -c
+@itemx --total
+@opindex -c
 @opindex --total
 @cindex grand total of file system size, usage and available space
 Print a grand total of all arguments after all arguments have
diff --git a/src/df.c b/src/df.c
index d579553bb..86a5d7fc0 100644
--- a/src/df.c
+++ b/src/df.c
@@ -247,7 +247,6 @@ enum
 {
   NO_SYNC_OPTION = CHAR_MAX + 1,
   SYNC_OPTION,
-  TOTAL_OPTION,
   OUTPUT_OPTION
 };
 
@@ -264,7 +263,7 @@ static struct option const long_options[] =
   {"print-type", no_argument, nullptr, 'T'},
   {"sync", no_argument, nullptr, SYNC_OPTION},
   {"no-sync", no_argument, nullptr, NO_SYNC_OPTION},
-  {"total", no_argument, nullptr, TOTAL_OPTION},
+  {"total", no_argument, nullptr, 'c'},
   {"type", required_argument, nullptr, 't'},
   {"exclude-type", required_argument, nullptr, 'x'},
   {GETOPT_HELP_OPTION_DECL},
@@ -1528,7 +1527,7 @@ or all file systems by default.\n\
       --sync            invoke sync before getting usage info\n\
 "), stdout);
       fputs (_("\
-      --total           elide all entries insignificant to available space,\n\
+  -c, --total           elide all entries insignificant to available space,\n\
                           and produce a grand total\n\
 "), stdout);
       fputs (_("\
@@ -1583,7 +1582,7 @@ main (int argc, char **argv)
   while (true)
     {
       int oi = -1;
-      int c = getopt_long (argc, argv, "aB:iF:hHklmPTt:vx:", long_options,
+      int c = getopt_long (argc, argv, "aB:ciF:hHklmPTt:vx:", long_options,
                            &oi);
       if (c == -1)
         break;
@@ -1685,7 +1684,7 @@ main (int argc, char **argv)
             decode_output_arg (optarg);
           break;
 
-        case TOTAL_OPTION:
+        case 'c':
           print_grand_total = true;
           break;
 
diff --git a/tests/df/total-verify.sh b/tests/df/total-verify.sh
index db4cf00cc..9558c25f3 100755
--- a/tests/df/total-verify.sh
+++ b/tests/df/total-verify.sh
@@ -52,16 +52,18 @@ while (<>)
 die "$0: missing line of totals\n";
 EOF
 
-# Use --block-size=512 to keep df from printing rounded-to-kilobyte
-# numbers which wouldn't necessarily add up to the displayed total.
-df --total -P --block-size=512 > space || framework_failure_
-cat space  # this helps when debugging any test failure
-df --total -i -P               > inode || framework_failure_
-cat inode
+for opt in --total -c; do
+  # Use --block-size=512 to keep df from printing rounded-to-kilobyte
+  # numbers which wouldn't necessarily add up to the displayed total.
+  df $opt -P --block-size=512 > space || framework_failure_
+  cat space  # this helps when debugging any test failure
+  df $opt -i -P               > inode || framework_failure_
+  cat inode
 
-$PERL check-df space || fail=1
-$PERL check-df inode || fail=1
+  $PERL check-df space || fail=1
+  $PERL check-df inode || fail=1
 
-test "$fail" = 1 && dump_mount_list_
+  test "$fail" = 1 && dump_mount_list_
+done
 
 Exit $fail
-- 
2.52.0


Reply via email to