Turn off abbreviation in getopt_long (optarg.h)?

Is it possible to disable the abbreviation in getopt_long()? On the man page:

Long option names may be abbreviated if the abbreviation is unique or is an exact match for> a specific parameter.

I want to do this because the specification that I got for the code snippet requires full-size exact matching flags, and there are many flags.

+3
source share
3 answers

Codeape

It seems that there is no way to disable the reduction function. You are not alone in wanting this feature. See: http://sourceware.org/bugzilla/show_bug.cgi?id=6863

, , glibc , "WONTFIX". : -\

+4

argp_parse() getopt() ( , BTW), ,

state->argv[ state->next - 2 ]

, .

+2

This is not an ideal solution, but you can check the exact argument given by the user after calling getopt_long () (usually inside the switch), as shown below:

if (strcmp(argv[optind-1], "--longoption") == 0)

optind indicates the next argument you need to process. This way you can access the original argument using optind-1.

0
source

Source: https://habr.com/ru/post/1796059/


All Articles