commit: a9c8b2a8bdde951788c9f9b17c88f9812b99d096
parent 951f0da1b0ca2763d05436f1d31fd0ca64f4537b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 25 Jul 2025 01:30:04 +0200
cmd/mkfifo: add support for long options
Diffstat:
1 file changed, 17 insertions(+), 0 deletions(-)
diff --git a/cmd/mkfifo.c b/cmd/mkfifo.c
@@ -4,6 +4,7 @@
#define _POSIX_C_SOURCE 200809L
+#include "../config.h"
#include "../libutils/getopt_nolong.h"
#include "../libutils/mode.h"
@@ -13,6 +14,9 @@
#include <string.h> // strerror
#include <sys/stat.h> // mkfifo
#include <unistd.h> // getopt
+#ifdef HAS_GETOPT_LONG
+#include <getopt.h>
+#endif
mode_t filemask;
const char *argv0 = "mkfifo";
@@ -30,7 +34,20 @@ main(int argc, char *argv[])
const char *errstr = NULL;
+#ifdef HAS_GETOPT_LONG
+ // Strictly for GNUisms compatibility so no long-only options
+ // clang-format off
+ static struct option opts[] = {
+ {"mode", required_argument, NULL, 'm'},
+ {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, "+:m:", opts, NULL)) != -1;)
+#else
for(int c = -1; (c = getopt_nolong(argc, argv, ":m:")) != -1;)
+#endif
{
switch(c)
{