From: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
To: dev@dpdk.org
Cc: Tyler Retzlaff <roretzla@microsoft.com>,
Nick Connolly <nick.connolly@mayadata.io>,
Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>,
Jerin Jacob <jerinj@marvell.com>,
Sunil Kumar Kori <skori@marvell.com>
Subject: [dpdk-dev] [PATCH 1/7] eal: add wrappers for POSIX string functions
Date: Sun, 21 Feb 2021 02:29:04 +0300 [thread overview]
Message-ID: <20210220232910.772-2-dmitry.kozliuk@gmail.com> (raw)
In-Reply-To: <20210220232910.772-1-dmitry.kozliuk@gmail.com>
POSIX strncasecmp(), strdup(), and strtok_r() have different names
on Windows, respectively, strnicmp(), _strdup(), and strtok_s().
Add wrappers as inline functions, because they're used from librte_kvargs,
and thus cannot be in librte_eal; besides, implementation is trivial.
Signed-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>
---
lib/librte_eal/common/eal_common_dev.c | 6 +--
lib/librte_eal/common/eal_common_devargs.c | 7 ++--
lib/librte_eal/common/eal_common_log.c | 5 ++-
lib/librte_eal/common/eal_common_options.c | 12 +++---
lib/librte_eal/common/eal_common_trace_ctf.c | 2 +-
.../common/eal_common_trace_utils.c | 2 +-
lib/librte_eal/include/rte_string_fns.h | 42 +++++++++++++++++++
7 files changed, 60 insertions(+), 16 deletions(-)
diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c
index 8a3bd3100..0a15fdcf7 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -462,7 +462,7 @@ rte_dev_event_callback_register(const char *device_name,
if (!device_name) {
event_cb->dev_name = NULL;
} else {
- event_cb->dev_name = strdup(device_name);
+ event_cb->dev_name = rte_strdup(device_name);
if (event_cb->dev_name == NULL) {
ret = -ENOMEM;
goto error;
@@ -630,10 +630,10 @@ dev_str_sane_copy(const char *str)
end = strcspn(str, ",/");
if (str[end] == ',') {
- copy = strdup(&str[end + 1]);
+ copy = rte_strdup(&str[end + 1]);
} else {
/* '/' or '\0' */
- copy = strdup("");
+ copy = rte_strdup("");
}
if (copy == NULL) {
rte_errno = ENOMEM;
diff --git a/lib/librte_eal/common/eal_common_devargs.c b/lib/librte_eal/common/eal_common_devargs.c
index fcf3d9a3c..14e082a27 100644
--- a/lib/librte_eal/common/eal_common_devargs.c
+++ b/lib/librte_eal/common/eal_common_devargs.c
@@ -18,6 +18,7 @@
#include <rte_errno.h>
#include <rte_kvargs.h>
#include <rte_log.h>
+#include <rte_string_fns.h>
#include <rte_tailq.h>
#include "eal_private.h"
@@ -75,7 +76,7 @@ rte_devargs_layers_parse(struct rte_devargs *devargs,
* anything and keep referring only to it.
*/
if (devargs->data != devstr) {
- devargs->data = strdup(devstr);
+ devargs->data = rte_strdup(devstr);
if (devargs->data == NULL) {
RTE_LOG(ERR, EAL, "OOM\n");
ret = -ENOMEM;
@@ -219,9 +220,9 @@ rte_devargs_parse(struct rte_devargs *da, const char *dev)
da->bus = bus;
/* Parse eventual device arguments */
if (devname[i] == ',')
- da->args = strdup(&devname[i + 1]);
+ da->args = rte_strdup(&devname[i + 1]);
else
- da->args = strdup("");
+ da->args = rte_strdup("");
if (da->args == NULL) {
RTE_LOG(ERR, EAL, "not enough memory to parse arguments\n");
return -ENOMEM;
diff --git a/lib/librte_eal/common/eal_common_log.c b/lib/librte_eal/common/eal_common_log.c
index c5554badb..557a8243f 100644
--- a/lib/librte_eal/common/eal_common_log.c
+++ b/lib/librte_eal/common/eal_common_log.c
@@ -14,6 +14,7 @@
#include <rte_eal.h>
#include <rte_log.h>
#include <rte_per_lcore.h>
+#include <rte_string_fns.h>
#include "eal_private.h"
@@ -194,7 +195,7 @@ static int rte_log_save_level(int priority,
if (regcomp(&opt_ll->re_match, regex, 0) != 0)
goto fail;
} else if (pattern) {
- opt_ll->pattern = strdup(pattern);
+ opt_ll->pattern = rte_strdup(pattern);
if (opt_ll->pattern == NULL)
goto fail;
} else
@@ -270,7 +271,7 @@ rte_log_lookup(const char *name)
static int
__rte_log_register(const char *name, int id)
{
- char *dup_name = strdup(name);
+ char *dup_name = rte_strdup(name);
if (dup_name == NULL)
return -ENOMEM;
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 622c7bc42..3612ad441 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c
@@ -228,7 +228,7 @@ eal_save_args(int argc, char **argv)
return -1;
for (i = 0; i < argc; i++) {
- eal_args[i] = strdup(argv[i]);
+ eal_args[i] = rte_strdup(argv[i]);
if (strcmp(argv[i], "--") == 0)
break;
}
@@ -243,7 +243,7 @@ eal_save_args(int argc, char **argv)
return -1;
for (j = 0; i < argc; j++, i++)
- eal_app_args[j] = strdup(argv[i]);
+ eal_app_args[j] = rte_strdup(argv[i]);
eal_app_args[j] = NULL;
return 0;
@@ -1273,7 +1273,7 @@ eal_parse_log_level(const char *arg)
char *str, *level;
int priority;
- str = strdup(arg);
+ str = rte_strdup(arg);
if (str == NULL)
return -1;
@@ -1324,11 +1324,11 @@ eal_parse_log_level(const char *arg)
static enum rte_proc_type_t
eal_parse_proc_type(const char *arg)
{
- if (strncasecmp(arg, "primary", sizeof("primary")) == 0)
+ if (rte_strncasecmp(arg, "primary", sizeof("primary")) == 0)
return RTE_PROC_PRIMARY;
- if (strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
+ if (rte_strncasecmp(arg, "secondary", sizeof("secondary")) == 0)
return RTE_PROC_SECONDARY;
- if (strncasecmp(arg, "auto", sizeof("auto")) == 0)
+ if (rte_strncasecmp(arg, "auto", sizeof("auto")) == 0)
return RTE_PROC_AUTO;
return RTE_PROC_INVALID;
diff --git a/lib/librte_eal/common/eal_common_trace_ctf.c b/lib/librte_eal/common/eal_common_trace_ctf.c
index 33e419aac..4041d9af6 100644
--- a/lib/librte_eal/common/eal_common_trace_ctf.c
+++ b/lib/librte_eal/common/eal_common_trace_ctf.c
@@ -398,7 +398,7 @@ char *trace_metadata_fixup_field(const char *field)
if (strstr(field, ".") == NULL && strstr(field, "->") == NULL)
return NULL;
- out = strdup(field);
+ out = rte_strdup(field);
if (out == NULL)
return NULL;
p = out;
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index 64f58fb66..d541a5ea9 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c
@@ -145,7 +145,7 @@ eal_trace_args_save(const char *val)
return -ENOMEM;
}
- arg->val = strdup(val);
+ arg->val = rte_strdup(val);
if (arg->val == NULL) {
trace_err("failed to allocate memory for %s", val);
free(arg);
diff --git a/lib/librte_eal/include/rte_string_fns.h b/lib/librte_eal/include/rte_string_fns.h
index 8bac8243c..2d9d5afc8 100644
--- a/lib/librte_eal/include/rte_string_fns.h
+++ b/lib/librte_eal/include/rte_string_fns.h
@@ -116,6 +116,48 @@ rte_strlcat(char *dst, const char *src, size_t size)
ssize_t
rte_strscpy(char *dst, const char *src, size_t dsize);
+/**
+ * @internal
+ * strncasecmp(3) replacement for systems that don't have it.
+ */
+static inline int
+rte_strncasecmp(const char *s1, const char *s2, size_t size)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+ return _strnicmp(s1, s2, size);
+#else
+ return strncasecmp(s1, s2, size);
+#endif
+}
+
+/**
+ * @internal
+ * strtor_r(3) replacement for systems that don't have it.
+ */
+static inline char *
+rte_strtok(char *str, const char *delim, char **saveptr)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+ return strtok_s(str, delim, saveptr);
+#else
+ return strtok_r(str, delim, saveptr);
+#endif
+}
+
+/**
+ * @internal
+ * strdup(3) replacement for systems that don't have it.
+ */
+static inline char *
+rte_strdup(const char *str)
+{
+#ifdef RTE_EXEC_ENV_WINDOWS
+ return _strdup(str);
+#else
+ return strdup(str);
+#endif
+}
+
#ifdef __cplusplus
}
#endif
--
2.29.2
next prev parent reply other threads:[~2021-02-20 23:29 UTC|newest]
Thread overview: 132+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-20 23:29 [dpdk-dev] [PATCH 0/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-02-20 23:29 ` Dmitry Kozlyuk [this message]
2021-02-20 23:29 ` [dpdk-dev] [PATCH 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
2021-02-20 23:29 ` [dpdk-dev] [PATCH 3/7] eal: add sleep API Dmitry Kozlyuk
2021-02-20 23:29 ` [dpdk-dev] [PATCH 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
2021-02-20 23:29 ` [dpdk-dev] [PATCH 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
2021-02-20 23:29 ` [dpdk-dev] [PATCH 6/7] drivers: " Dmitry Kozlyuk
2021-02-20 23:29 ` [dpdk-dev] [PATCH 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 0/7] " Dmitry Kozlyuk
2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
2021-02-22 11:47 ` Bruce Richardson
2021-02-22 12:48 ` Nick Connolly
2021-02-22 14:26 ` Bruce Richardson
2021-02-22 18:21 ` Nick Connolly
2021-02-22 22:57 ` Dmitry Kozlyuk
2021-02-23 9:45 ` Bruce Richardson
2021-02-27 20:23 ` Dmitry Kozlyuk
2021-03-01 21:31 ` Nick Connolly
2021-03-02 0:22 ` Dmitry Kozlyuk
2021-03-02 11:27 ` Nick Connolly
2021-03-16 9:51 ` Thomas Monjalon
2021-02-22 18:07 ` Tyler Retzlaff
2021-02-22 18:36 ` Nick Connolly
2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 3/7] eal: add sleep API Dmitry Kozlyuk
2021-02-21 8:58 ` Tal Shnaiderman
2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 6/7] drivers: " Dmitry Kozlyuk
2021-02-21 8:59 ` Tal Shnaiderman
2021-02-21 15:54 ` Andrew Rybchenko
2021-02-21 17:05 ` Dmitry Kozlyuk
2021-02-21 1:28 ` [dpdk-dev] [PATCH v2 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-02-21 8:59 ` Tal Shnaiderman
2021-02-21 10:24 ` Dmitry Kozlyuk
2021-02-21 11:58 ` Tal Shnaiderman
2021-02-21 14:33 ` Dmitry Kozlyuk
2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 0/7] " Dmitry Kozlyuk
2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 1/7] eal: add wrappers for POSIX string functions Dmitry Kozlyuk
2021-02-23 7:11 ` Andrew Rybchenko
2021-02-23 21:53 ` Nick Connolly
2021-02-24 7:21 ` Andrew Rybchenko
2021-03-04 6:47 ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 2/7] eal: add macro for maximum path length Dmitry Kozlyuk
2021-03-04 6:47 ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 3/7] eal: add sleep API Dmitry Kozlyuk
2021-02-23 22:06 ` Nick Connolly
2021-03-04 6:47 ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 4/7] eal: add asprintf() internal wrapper Dmitry Kozlyuk
2021-03-04 6:48 ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 5/7] lib: remove POSIX dependencies Dmitry Kozlyuk
2021-03-04 6:48 ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 6/7] drivers: " Dmitry Kozlyuk
2021-03-04 6:49 ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-02-21 14:28 ` [dpdk-dev] [PATCH v3 7/7] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-03-04 6:49 ` [dpdk-dev] [EXTERNAL] " Khoa To
2021-03-04 6:46 ` [dpdk-dev] [EXTERNAL] [PATCH v3 0/7] " Khoa To
2021-03-06 0:04 ` [dpdk-dev] [PATCH v4 0/4] " Dmitry Kozlyuk
2021-03-06 0:04 ` [dpdk-dev] [PATCH v4 1/4] eal: add sleep API Dmitry Kozlyuk
2021-03-06 0:04 ` [dpdk-dev] [PATCH v4 2/4] eal: add asprintf() internal wrapper Dmitry Kozlyuk
2021-03-06 15:27 ` Lance Richardson
2021-03-06 0:04 ` [dpdk-dev] [PATCH v4 3/4] build: indicate usage at build time for public headers Dmitry Kozlyuk
2021-03-16 9:59 ` Thomas Monjalon
2021-03-06 0:05 ` [dpdk-dev] [PATCH v4 4/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-03-17 19:23 ` [dpdk-dev] [PATCH v4 0/4] " Ranjit Menon
2021-03-20 11:27 ` [dpdk-dev] [PATCH v5 0/5] " Dmitry Kozlyuk
2021-03-20 11:27 ` [dpdk-dev] [PATCH v5 1/5] eal: add sleep API Dmitry Kozlyuk
2021-03-22 8:57 ` Kinsella, Ray
2021-03-20 11:27 ` [dpdk-dev] [PATCH v5 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
2021-03-20 11:27 ` [dpdk-dev] [PATCH v5 3/5] eal: make OS shims internal Dmitry Kozlyuk
2021-03-20 11:27 ` [dpdk-dev] [PATCH v5 4/5] net: provide IP-related API on any OS Dmitry Kozlyuk
2021-03-20 11:27 ` [dpdk-dev] [PATCH v5 5/5] net: replace Windows networking shim Dmitry Kozlyuk
2021-03-20 13:05 ` [dpdk-dev] [PATCH v6 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-03-20 13:05 ` [dpdk-dev] [PATCH v6 1/5] eal: add sleep API Dmitry Kozlyuk
2021-03-20 13:05 ` [dpdk-dev] [PATCH v6 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
2021-03-26 9:04 ` Thomas Monjalon
2021-03-20 13:05 ` [dpdk-dev] [PATCH v6 3/5] eal: make OS shims internal Dmitry Kozlyuk
2021-03-26 9:12 ` Thomas Monjalon
2021-03-31 21:05 ` Nick Connolly
2021-03-31 21:19 ` Thomas Monjalon
2021-03-31 21:45 ` Nick Connolly
2021-03-31 21:55 ` Thomas Monjalon
2021-04-01 23:10 ` Dmitry Kozlyuk
2021-04-01 23:18 ` Thomas Monjalon
2021-03-20 13:05 ` [dpdk-dev] [PATCH v6 4/5] net: provide IP-related API on any OS Dmitry Kozlyuk
2021-03-26 9:22 ` Thomas Monjalon
2021-03-20 13:05 ` [dpdk-dev] [PATCH v6 5/5] net: replace Windows networking shim Dmitry Kozlyuk
2021-03-26 9:28 ` Thomas Monjalon
2021-04-01 23:03 ` Dmitry Kozlyuk
2021-04-03 23:41 ` [dpdk-dev] [PATCH v7 0/5] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-04-03 23:41 ` [dpdk-dev] [PATCH v7 1/5] eal: add sleep API Dmitry Kozlyuk
2021-04-06 14:34 ` Morten Brørup
2021-04-06 23:29 ` Dmitry Kozlyuk
2021-04-07 7:31 ` Morten Brørup
2021-04-29 17:09 ` Tyler Retzlaff
2021-04-03 23:41 ` [dpdk-dev] [PATCH v7 2/5] eal/windows: hide asprintf() shim Dmitry Kozlyuk
2021-04-10 7:05 ` Nick Connolly
2021-04-03 23:41 ` [dpdk-dev] [PATCH v7 3/5] eal: make OS shims internal Dmitry Kozlyuk
2021-04-03 23:41 ` [dpdk-dev] [PATCH v7 4/5] net: work around s_addr macro on Windows Dmitry Kozlyuk
2021-04-03 23:41 ` [dpdk-dev] [PATCH v7 5/5] net: provide IP-related API on any OS Dmitry Kozlyuk
2021-04-07 22:22 ` [dpdk-dev] [PATCH v8 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-04-07 22:22 ` [dpdk-dev] [PATCH v8 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
2021-04-07 22:22 ` [dpdk-dev] [PATCH v8 2/4] eal: make OS shims internal Dmitry Kozlyuk
2021-04-07 22:22 ` [dpdk-dev] [PATCH v8 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
2021-04-08 11:26 ` Olivier Matz
2021-04-07 22:22 ` [dpdk-dev] [PATCH v8 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
2021-04-08 11:45 ` Olivier Matz
2021-04-08 19:51 ` Dmitry Kozlyuk
2021-04-09 13:33 ` Olivier Matz
2021-04-14 21:47 ` Thomas Monjalon
2021-04-10 22:47 ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Dmitry Kozlyuk
2021-04-10 22:47 ` [dpdk-dev] [PATCH v9 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
2021-04-10 22:47 ` [dpdk-dev] [PATCH v9 2/4] eal: make OS shims internal Dmitry Kozlyuk
2021-04-14 21:33 ` Thomas Monjalon
2021-04-10 22:47 ` [dpdk-dev] [PATCH v9 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
2021-04-10 22:47 ` [dpdk-dev] [PATCH v9 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
2021-04-13 4:46 ` [dpdk-dev] [PATCH v9 0/4] eal/windows: do not expose POSIX symbols Ranjit Menon
2021-04-13 7:00 ` Dmitry Kozlyuk
2021-04-14 21:12 ` Thomas Monjalon
2021-04-14 21:34 ` Ranjit Menon
2021-04-14 21:42 ` Thomas Monjalon
2021-04-14 21:47 ` Ranjit Menon
2021-04-14 22:08 ` Dmitry Kozlyuk
2021-04-14 22:58 ` Thomas Monjalon
2021-04-14 22:06 ` [dpdk-dev] [PATCH v10 " Dmitry Kozlyuk
2021-04-14 22:06 ` [dpdk-dev] [PATCH v10 1/4] eal/windows: hide asprintf() shim Dmitry Kozlyuk
2021-04-14 22:06 ` [dpdk-dev] [PATCH v10 2/4] eal: make OS shims internal Dmitry Kozlyuk
2021-04-14 22:06 ` [dpdk-dev] [PATCH v10 3/4] net: work around s_addr macro on Windows Dmitry Kozlyuk
2021-04-14 22:06 ` [dpdk-dev] [PATCH v10 4/4] net: provide IP-related API on any OS Dmitry Kozlyuk
2021-04-14 22:50 ` [dpdk-dev] [PATCH v10 0/4] eal/windows: do not expose POSIX symbols Ranjit Menon
2021-04-14 23:57 ` Thomas Monjalon
2021-03-17 19:19 ` [dpdk-dev] [PATCH 0/7] " Ranjit Menon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210220232910.772-2-dmitry.kozliuk@gmail.com \
--to=dmitry.kozliuk@gmail.com \
--cc=dev@dpdk.org \
--cc=jerinj@marvell.com \
--cc=nick.connolly@mayadata.io \
--cc=roretzla@microsoft.com \
--cc=skori@marvell.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).