commit: 9dcc738abc5744c3f5ce91e27132cb185b9d2036
parent 1691cd389846d34cdcba39514d71a5fb5b16a2f5
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 25 Jul 2025 01:08:35 +0200
cmd/df: add support for long options
Diffstat:
1 file changed, 23 insertions(+), 0 deletions(-)
diff --git a/cmd/df.c b/cmd/df.c
@@ -5,6 +5,7 @@
#define _POSIX_C_SOURCE 202405L
#define _DEFAULT_SOURCE // mntent in glibc 2.19+
+#include "../config.h"
#include "../lib/reallocarray.h"
#include "../libutils/getopt_nolong.h"
#include "../libutils/humanize.h"
@@ -19,6 +20,9 @@
#include <sys/stat.h> // stat, dev_t
#include <sys/statvfs.h>
#include <unistd.h> // getopt
+#ifdef HAS_GETOPT_LONG
+#include <getopt.h>
+#endif
#define STR(s) #s
@@ -62,7 +66,26 @@ main(int argc, char *argv[])
size_t only_count = 0;
static char *only[DF_MNT_TYPE_MAX];
+#ifdef HAS_GETOPT_LONG
+ // Strictly for GNUisms compatibility so no long-only options
+ // clang-format off
+ static struct option opts[] = {
+ {"all", no_argument, NULL, 'a'},
+ {"human-readable", no_argument, NULL, 'h'},
+ {"inodes", no_argument, NULL, 'i'},
+ {"local", no_argument, NULL, 'l'},
+ {"portability", no_argument, NULL, 'P'},
+ {"type", required_argument, NULL, 't'},
+ {"exclude-type", required_argument, NULL, 'x'},
+ {0, 0, 0, 0},
+ };
+ // clang-format on
+
+ // Need + as first character to get POSIX-style option parsing
+ for(int c = -1; (c = getopt_long(argc, argv, "+:ahilPkTt:x:", opts, NULL)) != -1;)
+#else
for(int c = -1; (c = getopt_nolong(argc, argv, ":ahilPkTt:x:")) != -1;)
+#endif
{
switch(c)
{