MCPcopy Create free account
hub / github.com/OpenVPN/openvpn3-linux / init_getopt

Method init_getopt

src/common/cmdargparser.cpp:842–872  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

840
841
842struct option *SingleCommand::init_getopt()
843{
844 unsigned int idx = 0;
845 shortopts = "";
846 struct option *result = (struct option *)calloc(options.size() + 2,
847 sizeof(struct option));
848 if (result == NULL)
849 {
850 throw CommandException(command, "Failed to allocate memory for option parsing");
851 }
852
853 // Parse through all registered options
854 for (auto const &opt : options)
855 {
856 // Apply the option definition into the pre-defined designated
857 // slot
858 for (const auto &o : opt->get_struct_option())
859 {
860 memcpy(&result[idx], o, sizeof(struct option));
861 idx++;
862 }
863
864 // Collect all we need for the short flags too
865 shortopts += opt->getopt_optstring();
866 }
867
868 // getopt_long() expects the last record in the struct option array
869 // to be an empty/zeroed struct option element
870 result[idx] = {0};
871 return result;
872}
873
874
875std::string SingleCommand::gen_help(const std::string arg0)

Callers

nothing calls this directly

Calls 4

CommandExceptionClass · 0.85
sizeMethod · 0.80
get_struct_optionMethod · 0.80
getopt_optstringMethod · 0.80

Tested by

no test coverage detected