New upstream version 18.11-rc1
[deb_dpdk.git] / lib / librte_eal / common / rte_option.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018 Intel Corporation.
3  */
4
5 #include <unistd.h>
6 #include <string.h>
7
8 #include <rte_eal.h>
9 #include <rte_option.h>
10
11 #include "eal_private.h"
12
13 TAILQ_HEAD(rte_option_list, rte_option);
14
15 struct rte_option_list rte_option_list =
16         TAILQ_HEAD_INITIALIZER(rte_option_list);
17
18 static struct rte_option *option;
19
20 int
21 rte_option_parse(const char *opt)
22 {
23         /* Check if the option is registered */
24         TAILQ_FOREACH(option, &rte_option_list, next) {
25                 if (strcmp(opt, option->opt_str) == 0) {
26                         option->enabled = 1;
27                         return 0;
28                 }
29         }
30
31         return -1;
32 }
33
34 void __rte_experimental
35 rte_option_register(struct rte_option *opt)
36 {
37         TAILQ_FOREACH(option, &rte_option_list, next) {
38                 if (strcmp(opt->opt_str, option->opt_str) == 0)
39                         RTE_LOG(INFO, EAL, "Option %s has already been registered.",
40                                         opt->opt_str);
41                         return;
42         }
43
44         TAILQ_INSERT_HEAD(&rte_option_list, opt, next);
45 }
46
47 void
48 rte_option_init(void)
49 {
50         TAILQ_FOREACH(option, &rte_option_list, next) {
51                 if (option->enabled)
52                         option->cb();
53         }
54 }