commit: 08efe9261e124f49e943c0a497e246bee873f08b
parent b9383ca5a8a261c234d43c81d7e2f1366568a63d
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sun, 28 Jul 2024 05:37:22 +0200
cmd/rmdir: Add getopt_long compatibility
Diffstat:
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/cmd/rmdir.c b/cmd/rmdir.c
@@ -9,6 +9,9 @@
#include <stdlib.h> // abort
#include <string.h> // strerror, strrchr
#include <unistd.h> // getopt, rmdir
+#ifdef HAS_GETOPT_LONG
+#include <getopt.h>
+#endif
static void
usage()
@@ -22,7 +25,21 @@ main(int argc, char *argv[])
bool parents = false, verbose = false;
int c = -1;
+#ifdef HAS_GETOPT_LONG
+ // Strictly for GNUisms compatibility so no long-only options
+ // clang-format off
+ static struct option opts[] = {
+ {"parents", no_argument, 0, 'p'},
+ {"verbose", no_argument, 0, 'v'},
+ {0, 0, 0, 0},
+ };
+ // clang-format on
+
+ // Need + as first character to get POSIX-style option parsing
+ while((c = getopt_long(argc, argv, "+:pv", opts, NULL)) != -1)
+#else
while((c = getopt(argc, argv, ":pv")) != -1)
+#endif
{
switch(c)
{