#define _GNU_SOURCE #include #include #include struct option options[] = { { "stop-at-entry", 0, 0, 's' }, { "shell", 1, 0, 'c' }, { NULL, 0, 0, 0 } }; extern int optreset; int main(void) { int val; optind = 1; //optreset = 1; int argc = 3; char *argv[] = {"dummy_arg", "--shell=/bin/sh", "--", NULL}; int longindex = -1; char *optstring = "sc::"; printf("**optind is %d, argv[%d] is %s\n", optind, optind, argv[optind]); val = getopt_long_only(argc, argv, optstring, &options[0], &longindex); if (val != 'c') { printf ("%d: getopt_long_only FAIL\n", __LINE__); return 1; } printf("**optind is %d, argv[%d] is %s\n", optind, optind, argv[optind]); val = getopt_long_only(argc, argv, optstring, &options[0], &longindex); if (val != -1) { printf ("%d: getopt_long_only FAIL\n", __LINE__); return 1; } return 0; }