logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: ffcd08e7834f1fe635ce8caec6481f9c8656a9f3
parent a7c8206ff7ca98fc956e2d6763f6cbcbb8bbe070
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Fri, 25 Jul 2025 04:28:35 +0200

cmd/sync: add support for long options

Diffstat:

Mcmd/sync.c17+++++++++++++++++
1 file changed, 17 insertions(+), 0 deletions(-)

diff --git a/cmd/sync.c b/cmd/sync.c @@ -16,6 +16,9 @@ #include <stdlib.h> // abort #include <string.h> // strerror #include <unistd.h> // fsync, sync, getopt, syncfs +#ifdef HAS_GETOPT_LONG +#include <getopt.h> +#endif const char *argv0 = "sync"; @@ -25,7 +28,21 @@ main(int argc, char *argv[]) int err = 0; int (*sync_func)(int) = fsync; +#ifdef HAS_GETOPT_LONG + // Strictly for GNUisms compatibility so no long-only options + // clang-format off + static struct option opts[] = { + {"data", no_argument, NULL, 'd'}, + {"file-system", no_argument, NULL, 'f'}, + {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, "+:df", opts, NULL)) != -1;) +#else for(int c = -1; (c = getopt_nolong(argc, argv, ":df")) != -1;) +#endif { switch(c) {