diff mbox series

[5/7] lib: remove POSIX dependencies

Message ID 20210220232910.772-6-dmitry.kozliuk@gmail.com (mailing list archive)
State Superseded, archived
Headers show
Series eal/windows: do not expose POSIX symbols | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Dmitry Kozlyuk Feb. 20, 2021, 11:29 p.m. UTC
Replace POSIX strtok_r() with EAL rte_strtok().
Replace POSIX strdup()   with EAL rte_strdup().
Locally rename Windows _close() to standard close().

Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
 lib/librte_cmdline/cmdline.c      |  1 +
 lib/librte_ethdev/rte_class_eth.c |  2 +-
 lib/librte_ethdev/rte_ethdev.c    |  2 +-
 lib/librte_kvargs/rte_kvargs.c    | 17 ++++++++++-------
 4 files changed, 13 insertions(+), 9 deletions(-)
diff mbox series

Patch

diff --git a/lib/librte_cmdline/cmdline.c b/lib/librte_cmdline/cmdline.c
index 79ea5f98c..4dfa1178f 100644
--- a/lib/librte_cmdline/cmdline.c
+++ b/lib/librte_cmdline/cmdline.c
@@ -19,6 +19,7 @@ 
 #include "cmdline_private.h"
 
 #ifdef RTE_EXEC_ENV_WINDOWS
+#define close _close
 #define write _write
 #endif
 
diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c
index ca2ce87f7..9b72bdf15 100644
--- a/lib/librte_ethdev/rte_class_eth.c
+++ b/lib/librte_ethdev/rte_class_eth.c
@@ -73,7 +73,7 @@  eth_representor_cmp(const char *key __rte_unused,
 		return -1; /* not a representor port */
 
 	/* Parse devargs representor values. */
-	values = strdup(value);
+	values = rte_strdup(value);
 	if (values == NULL)
 		return -1;
 	memset(&representors, 0, sizeof(representors));
diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index 6f514c388..a09fec2ce 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -5515,7 +5515,7 @@  eth_dev_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in)
 	struct rte_kvargs_pair *pair;
 	char *letter;
 
-	arglist->str = strdup(str_in);
+	arglist->str = rte_strdup(str_in);
 	if (arglist->str == NULL)
 		return -ENOMEM;
 
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 285081c86..fd1103b33 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -26,20 +26,22 @@  rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 	/* Copy the const char *params to a modifiable string
 	 * to pass to rte_strsplit
 	 */
-	kvlist->str = strdup(params);
+	kvlist->str = rte_strdup(params);
 	if (kvlist->str == NULL)
 		return -1;
 
 	/* browse each key/value pair and add it in kvlist */
 	str = kvlist->str;
-	while ((str = strtok_r(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {
+	while ((str = rte_strtok(str, RTE_KVARGS_PAIRS_DELIM, &ctx1)) != NULL) {
 
 		i = kvlist->count;
 		if (i >= RTE_KVARGS_MAX)
 			return -1;
 
-		kvlist->pairs[i].key = strtok_r(str, RTE_KVARGS_KV_DELIM, &ctx2);
-		kvlist->pairs[i].value = strtok_r(NULL, RTE_KVARGS_KV_DELIM, &ctx2);
+		kvlist->pairs[i].key = rte_strtok(
+			str, RTE_KVARGS_KV_DELIM, &ctx2);
+		kvlist->pairs[i].value = rte_strtok(
+			NULL, RTE_KVARGS_KV_DELIM, &ctx2);
 		if (kvlist->pairs[i].key == NULL ||
 		    kvlist->pairs[i].value == NULL)
 			return -1;
@@ -49,12 +51,13 @@  rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
 		if (str[0] == '[') {
 			/* Find the end of the list. */
 			while (str[strlen(str) - 1] != ']') {
-				/* Restore the comma erased by strtok_r(). */
+				/* Restore the comma erased by rte_strtok(). */
 				if (ctx1 == NULL || ctx1[0] == '\0')
 					return -1; /* no closing bracket */
 				str[strlen(str)] = ',';
 				/* Parse until next comma. */
-				str = strtok_r(NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
+				str = rte_strtok(
+					NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
 				if (str == NULL)
 					return -1; /* no closing bracket */
 			}
@@ -199,7 +202,7 @@  rte_kvargs_parse_delim(const char *args, const char * const valid_keys[],
 	if (valid_ends == NULL)
 		return rte_kvargs_parse(args, valid_keys);
 
-	copy = strdup(args);
+	copy = rte_strdup(args);
 	if (copy == NULL)
 		return NULL;