getopt_long_test.c (676B)
- // Collection of Unix tools, comparable to coreutils
- // SPDX-FileCopyrightText: 2017-2023 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
- #define _GNU_SOURCE
- #include <getopt.h> // getopt_long
- #include <unistd.h> // opt*
- int
- main(int argc, char *argv[])
- {
- static struct option longopts[] = {{"unset", required_argument, NULL, 'u'}, {NULL, 0, NULL, 0}};
- int c = 0;
- while((c = getopt_long(argc, argv, "+:iu:", longopts, NULL)) != -1)
- {
- switch(c)
- {
- case 'u':
- // option processing would go here
- break;
- default:
- return 1;
- }
- }
- argc -= optind;
- argv += optind;
- }