commit: c173856663cfaf01033274a7f5f2d4077d4fc018
parent 58f36fd6e0c32dcbb73e95e5961f6980a8f69b43
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 25 Jul 2025 02:26:01 +0200
cmd/pwd: add support for long options
Diffstat:
1 file changed, 18 insertions(+), 0 deletions(-)
diff --git a/cmd/pwd.c b/cmd/pwd.c
@@ -3,6 +3,7 @@
// SPDX-License-Identifier: MPL-2.0
#define _POSIX_C_SOURCE 200809L
+#include "../config.h"
#include "../libutils/getopt_nolong.h"
#include <limits.h> // PATH_MAX
@@ -11,6 +12,9 @@
#include <stdlib.h> // getenv
#include <sys/stat.h>
#include <unistd.h> // getcwd
+#ifdef HAS_GETOPT_LONG
+#include <getopt.h>
+#endif
const char *argv0 = "pwd";
@@ -76,7 +80,21 @@ main(int argc, char *argv[])
{
enum pwd mode = PWD_L;
+#ifdef HAS_GETOPT_LONG
+ // Strictly for GNUisms compatibility so no long-only options
+ // clang-format off
+ static struct option opts[] = {
+ {"logical", no_argument, NULL, 'L'},
+ {"physical", no_argument, NULL, 'P'},
+ {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, "+:LP", opts, NULL)) != -1;)
+#else
for(int c = -1; (c = getopt_nolong(argc, argv, ":LP")) != -1;)
+#endif
{
switch(c)
{