diff options
author | Ciprian Barbu <ciprian.barbu@linaro.org> | 2015-01-12 12:50:19 +0200 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2015-01-14 16:58:10 +0300 |
commit | 273955e6db6bb220f2736d3709e4237c50d04772 (patch) | |
tree | 7a64d1ac4e565467c2ed312f09dc5d3989f72e43 /example/packet | |
parent | 68c7b7e88b1b948868d35497e715cf5077e90e40 (diff) |
example: pktio: replace strtok_r to make C99 compliant
Signed-off-by: Ciprian Barbu <ciprian.barbu@linaro.org>
Reviewed-and-tested-by: Mike Holmes <mike.holmes@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
Diffstat (limited to 'example/packet')
-rw-r--r-- | example/packet/odp_pktio.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/example/packet/odp_pktio.c b/example/packet/odp_pktio.c index b162fac..0d5918a 100644 --- a/example/packet/odp_pktio.c +++ b/example/packet/odp_pktio.c @@ -69,6 +69,7 @@ typedef struct { int if_count; /**< Number of interfaces to be used */ char **if_names; /**< Array of pointers to interface names */ int mode; /**< Packet IO mode */ + char *if_str; /**< Storage for interface names */ } appl_args_t; /** @@ -376,6 +377,8 @@ int main(int argc, char *argv[]) /* Master thread waits for other threads to exit */ odph_linux_pthread_join(thread_tbl, num_workers); + free(args->appl.if_names); + free(args->appl.if_str); free(args); printf("Exit\n\n"); @@ -462,7 +465,7 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) { int opt; int long_index; - char *names, *str, *token, *save; + char *token; size_t len; int i; static struct option longopts[] = { @@ -495,19 +498,19 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) } len += 1; /* add room for '\0' */ - names = malloc(len); - if (names == NULL) { + appl_args->if_str = malloc(len); + if (appl_args->if_str == NULL) { usage(argv[0]); exit(EXIT_FAILURE); } /* count the number of tokens separated by ',' */ - strcpy(names, optarg); - for (str = names, i = 0;; str = NULL, i++) { - token = strtok_r(str, ",", &save); - if (token == NULL) - break; - } + strcpy(appl_args->if_str, optarg); + for (token = strtok(appl_args->if_str, ","), i = 0; + token != NULL; + token = strtok(NULL, ","), i++) + ; + appl_args->if_count = i; if (appl_args->if_count == 0) { @@ -520,11 +523,9 @@ static void parse_args(int argc, char *argv[], appl_args_t *appl_args) calloc(appl_args->if_count, sizeof(char *)); /* store the if names (reset names string) */ - strcpy(names, optarg); - for (str = names, i = 0;; str = NULL, i++) { - token = strtok_r(str, ",", &save); - if (token == NULL) - break; + strcpy(appl_args->if_str, optarg); + for (token = strtok(appl_args->if_str, ","), i = 0; + token != NULL; token = strtok(NULL, ","), i++) { appl_args->if_names[i] = token; } break; |