logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git

getopt_long_test.c (676B)


  1. // Collection of Unix tools, comparable to coreutils
  2. // SPDX-FileCopyrightText: 2017-2023 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. // SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
  4. #define _GNU_SOURCE
  5. #include <getopt.h> // getopt_long
  6. #include <unistd.h> // opt*
  7. int
  8. main(int argc, char *argv[])
  9. {
  10. static struct option longopts[] = {{"unset", required_argument, NULL, 'u'}, {NULL, 0, NULL, 0}};
  11. int c = 0;
  12. while((c = getopt_long(argc, argv, "+:iu:", longopts, NULL)) != -1)
  13. {
  14. switch(c)
  15. {
  16. case 'u':
  17. // option processing would go here
  18. break;
  19. default:
  20. return 1;
  21. }
  22. }
  23. argc -= optind;
  24. argv += optind;
  25. }