45 #define GETOPT_ERROR(...) fprintf(stderr, __VA_ARGS__) 59 optstring(_optstring),
89 if (place[0] && place[0] ==
'-' && place[1] ==
'\0')
96 if (place[0] && place[0] ==
'-' && place[1])
104 namelen = strcspn(place,
"=");
105 for (i = 0; longopts[i].name !=
nullptr; i++)
107 if (strlen(longopts[i].
name) == namelen
108 && strncmp(place, longopts[i].name, namelen) == 0)
110 if (longopts[i].has_arg)
112 if (place[namelen] ==
'=')
113 optarg = place + namelen + 1;
114 else if (optind < argc - 1)
117 optarg = argv[optind];
121 if (optstring[0] ==
':')
124 GETOPT_ERROR(
"%s: option requires an argument -- %s\n",
135 if (place[namelen] != 0)
147 if (longopts[i].
flag ==
nullptr)
148 return longopts[i].val;
151 *longopts[i].flag = longopts[i].val;
157 if (opterr && optstring[0] !=
':') {
158 GETOPT_ERROR(
"%s: illegal option -- %s\n", argv[0], place);
167 optopt = (int) *place++;
169 oli = strchr(optstring, optopt);
174 if (opterr && *optstring !=
':') {
175 GETOPT_ERROR(
"%s: illegal option -- %c\n", argv[0], optopt);
190 else if (argc <= ++optind)
193 if (*optstring ==
':')
196 GETOPT_ERROR(
"%s: option requires an argument -- %c\n",
203 optarg = argv[optind];
210 #endif // HAL_OS_POSIX_IO
GetOptLong(int argc, char *const argv[], const char *optstring, const option *longopts)
void uint32_t uint32_t uint32_t flag