logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/

getopt_nolong.h (1464B)


  1. // utils-std: Collection of commonly available Unix tools
  2. // SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. // SPDX-License-Identifier: MPL-2.0
  4. #include <stdbool.h>
  5. extern const char *argv0;
  6. extern bool got_long_opt;
  7. int getopt_nolong(int argc, char *const argv[], const char *optstring);
  8. #ifdef HAS_GETOPT_LONG
  9. #define GETOPT_UNKNOWN_OPT \
  10. if(argv[optind - 1] && argv[optind - 1][0] == '-' && argv[optind - 1][1] == '-' && \
  11. argv[optind - 1][2] != '\0') \
  12. { \
  13. fprintf(stderr, "%s: error: Unrecognised long option: '%s'\n", argv0, argv[optind - 1]); \
  14. } \
  15. else if(!got_long_opt) \
  16. { \
  17. fprintf(stderr, "%s: error: Unrecognised option: '-%c'\n", argv0, optopt); \
  18. }
  19. #else
  20. #define GETOPT_UNKNOWN_OPT \
  21. if(!got_long_opt) fprintf(stderr, "%s: error: Unrecognised option: '-%c'\n", argv0, optopt);
  22. #endif