commit: 0de50355e73a41d4575f9440ed8016c7fdf6ebe5
parent 5888dc95144cf032f95ae8c801eb6df4838ac56c
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Thu, 24 Jul 2025 22:01:19 +0200
cmd/base64: add support for long options
Diffstat:
1 file changed, 18 insertions(+), 0 deletions(-)
diff --git a/cmd/base64.c b/cmd/base64.c
@@ -4,6 +4,7 @@
// SPDX-License-Identifier: MPL-2.0 AND BSD-2-Clause
#define _POSIX_C_SOURCE 200809L
+#include "../config.h"
#include "../libutils/getopt_nolong.h"
#include <assert.h> /* assert */
@@ -15,6 +16,9 @@
#include <string.h> /* strerror(), strncmp() */
#include <sys/stat.h> /* fstat */
#include <unistd.h> /* read(), write(), close(), getopt() */
+#ifdef HAS_GETOPT_LONG
+#include <getopt.h>
+#endif
// 64(26+26+10+2) + NULL
static const char *b64_encmap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -263,7 +267,21 @@ base64_main(int argc, char *argv[])
int ret = 0;
+#ifdef HAS_GETOPT_LONG
+ // Strictly for GNUisms compatibility so no long-only options
+ // clang-format off
+ static struct option opts[] = {
+ {"decode", no_argument, NULL, 'd'},
+ {"wrap", required_argument, NULL, 'w'},
+ {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, "+:dw:", opts, NULL)) != -1;)
+#else
for(int c = -1; (c = getopt_nolong(argc, argv, ":dw:")) != -1;)
+#endif
{
switch(c)
{