aboutsummaryrefslogtreecommitdiff
path: root/helper
diff options
context:
space:
mode:
authorPetri Savolainen <petri.savolainen@linaro.org>2018-05-16 09:56:19 +0300
committerPetri Savolainen <petri.savolainen@linaro.org>2018-05-16 09:56:19 +0300
commita0f68377b5123e6195f68dcfaf358798429a7ee6 (patch)
tree9e65b8629542ea3730ad02174eb5e13ec3359e6c /helper
parentc484446b4930b5398e958f855917d54a97e6f2c7 (diff)
parent0ee8255c2555ed68721ea5e7679f26a2e53bd8b8 (diff)
Merge branch 'master' of https://github.com/Linaro/odp into odp-dpdk
Diffstat (limited to 'helper')
-rw-r--r--helper/include/odp/helper/threads.h75
-rw-r--r--helper/test/odpthreads.c2
-rw-r--r--helper/threads.c131
3 files changed, 25 insertions, 183 deletions
diff --git a/helper/include/odp/helper/threads.h b/helper/include/odp/helper/threads.h
index ed7d7f39a..9d03c7192 100644
--- a/helper/include/odp/helper/threads.h
+++ b/helper/include/odp/helper/threads.h
@@ -146,74 +146,19 @@ int odph_odpthread_setaffinity(const int cpu);
int odph_odpthread_getaffinity(void);
/**
- * Merge getopt options
- *
- * Given two sets of getopt options (each containing possibly both short
- * options -a string- and long options -a option array-) this function
- * return a single set (i.e. a string for short and an array for long)
- * being the concatenation of the two given sets.
- * Due to the fact that the size of these arrays is unknown at compilation
- * time, this function actually mallocs the the resulting arrays.
- * The fourth and fith parameters are actually pointers where these malloc'ed
- * areas are returned.
- * This means that the caller of this function has to free the two returned
- * areas!
- *
- * @param shortopts1 first set of short options (a string)
- * @param shortopts2 second set of short options (a string)
- * @param longopts1 first set of long options (a getopt option array)
- * @param longopts2 second set of long options (a getopt option array)
- * @param shortopts a pointer where the address of the short options list
- * (a string) is returned. It contains the concatenation of
- * the two given short option strings.
- * @param longopts a pointer where the address of the long options list
- * (a getopt option array) is returned.
- * It contains the concatenation of the two given long
- * option arrays.
- * if any of shortopts1, shortopts2, longopts1, longopts2 is NULL, the
- * corresponding list as assumed to be empty.
- * if any of shortopts, longopts is NULL, the corresponding malloc is not
- * performed.
- *
- * @return On success: 0 : both shortopts and longopts are returned (assuming
- * the given pointer where not null), possibly
- * pointing to an empty string or an empty option array.
- * On success, the caller is due to free these areas.
- * On failure: -1: Nothing is malloc'ed.
- */
-int odph_merge_getopt_options(const char *shortopts1,
- const char *shortopts2,
- const struct option *longopts1,
- const struct option *longopts2,
- char **shortopts,
- struct option **longopts);
-
-/**
* Parse linux helper options
*
- * Parse the command line options. Pick up options meant for the helper itself.
- * If the caller is also having a set of option to parse, it should include
- * their description here (shortopts desribes the short options and longopts
- * describes the long options, as for getopt_long()).
- * This function will issue errors on unknown arguments, so callers failing
- * to pass their own command line options description here will see their
- * options rejected.
- * (the caller wants to set opterr to zero when parsing its own stuff
- * with getopts to avoid reacting on helper's options).
- *
- * @param argc argument count
- * @param argv argument values
- * @param caller_shortopts caller's set of short options (string). or NULL.
- * @param caller_longopts caller's set of long options (getopt option array).
- * or NULL.
- *
- * @return On success: 0
- * On failure: -1 failure occurs if a value passed for a helper
- * option is invalid, or on meeting unknown options.
+ * Parse the command line options. Pick up (--odph_ prefixed) options meant for
+ * the helper itself. When helper options are found, those are removed from
+ * argv[] and remaining options are packed to the beginning of the array.
+ *
+ * @param argc Argument count
+ * @param argv Argument vector
+ *
+ * @return New argument count. Original argument count decremented by
+ * the number of removed helper options.
*/
-int odph_parse_options(int argc, char *argv[],
- const char *caller_shortopts,
- const struct option *caller_longopts);
+int odph_parse_options(int argc, char *argv[]);
/**
* @}
diff --git a/helper/test/odpthreads.c b/helper/test/odpthreads.c
index aa61e6352..ad48ec2d5 100644
--- a/helper/test/odpthreads.c
+++ b/helper/test/odpthreads.c
@@ -73,7 +73,7 @@ int main(int argc, char *argv[])
char cpumaskstr[ODP_CPUMASK_STR_SIZE];
/* let helper collect its own arguments (e.g. --odph_proc) */
- odph_parse_options(argc, argv, NULL, NULL);
+ argc = odph_parse_options(argc, argv);
if (odp_init_global(&odp_instance, NULL, NULL)) {
ODPH_ERR("Error: ODP global init failed.\n");
diff --git a/helper/threads.c b/helper/threads.c
index f9216c7ed..86d6bf7be 100644
--- a/helper/threads.c
+++ b/helper/threads.c
@@ -330,129 +330,26 @@ int odph_odpthread_getaffinity(void)
return -1;
}
-/*
- * return the number of elements in an array of getopt options, excluding the
- * terminating {0,0,0,0}
- */
-static int get_getopt_options_length(const struct option *longopts)
+int odph_parse_options(int argc, char *argv[])
{
- int l = 0;
-
- if (!longopts)
- return 0;
-
- while (longopts[l].name)
- l++;
-
- return l;
-}
-
-/* Merge getopt options */
-int odph_merge_getopt_options(const char *shortopts1,
- const char *shortopts2,
- const struct option *longopts1,
- const struct option *longopts2,
- char **shortopts,
- struct option **longopts)
-{
- int shortopts1_len;
- int shortopts2_len;
- int longopts1_len;
- int longopts2_len;
- int index;
- int res_index = 0;
- struct option termination = {0, 0, 0, 0};
-
- /* merge short options: */
- if (shortopts) {
- shortopts1_len = (shortopts1) ? strlen(shortopts1) : 0;
- shortopts2_len = (shortopts2) ? strlen(shortopts2) : 0;
- *shortopts = malloc(shortopts1_len + shortopts2_len + 1);
- if (!*shortopts)
- return -1;
-
- (*shortopts)[0] = 0;
-
- if (shortopts1)
- strcpy((*shortopts), shortopts1);
- if (shortopts2)
- strcat((*shortopts), shortopts2);
- }
-
- /* merge long options */
- if (!longopts)
- return 0;
-
- longopts1_len = get_getopt_options_length(longopts1);
- longopts2_len = get_getopt_options_length(longopts2);
- *longopts = malloc(sizeof(struct option) *
- (longopts1_len + longopts2_len + 1));
- if (!*longopts) {
- if (shortopts)
- free(*shortopts);
- return -1;
- }
+ int i, j;
- for (index = 0; (longopts1) && (longopts1[index].name); index++)
- (*longopts)[res_index++] = longopts1[index];
+ helper_options.proc = 0;
- for (index = 0; (longopts2) && (longopts2[index].name); index++)
- (*longopts)[res_index++] = longopts2[index];
+ /* Find and remove option */
+ for (i = 0; i < argc;) {
+ if (strcmp(argv[i], "--odph_proc") == 0) {
+ helper_options.proc = 1;
- (*longopts)[res_index] = termination;
+ for (j = i; j < argc - 1; j++)
+ argv[j] = argv[j + 1];
- return 0;
-}
-
-/*
- * Parse command line options to extract options affecting helpers.
- */
-int odph_parse_options(int argc, char *argv[],
- const char *caller_shortopts,
- const struct option *caller_longopts)
-{
- int c;
- char *shortopts;
- struct option *longopts;
- int res = 0;
-
- static struct option helper_long_options[] = {
- /* These options set a flag. */
- {"odph_proc", no_argument, &helper_options.proc, 1},
- {0, 0, 0, 0}
- };
-
- static const char *helper_short_options = "";
-
- /* defaults: */
- helper_options.proc = false;
-
- /* merge caller's command line options descriptions with helper's: */
- if (odph_merge_getopt_options(caller_shortopts, helper_short_options,
- caller_longopts, helper_long_options,
- &shortopts, &longopts) < 0)
- return -1;
-
- while (1) {
- /* getopt_long stores the option index here. */
- int option_index = 0;
-
- c = getopt_long (argc, argv,
- shortopts, longopts, &option_index);
-
- /* Detect the end of the options. */
- if (c == -1)
- break;
+ argc--;
+ continue;
+ }
- /* check for unknown options or missing arguments */
- if (c == '?' || c == ':')
- res = -1;
+ i++;
}
- optind = 0; /* caller expects this to be zero if it parses too*/
-
- free(shortopts);
- free(longopts);
-
- return res;
+ return argc;
}