From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 95E56A034F; Sun, 21 Feb 2021 02:28:47 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 4B5B522A25A; Sun, 21 Feb 2021 02:28:42 +0100 (CET) Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by mails.dpdk.org (Postfix) with ESMTP id 3FF7922A25D for ; Sun, 21 Feb 2021 02:28:41 +0100 (CET) Received: by mail-lj1-f176.google.com with SMTP id o16so39895190ljj.11 for ; Sat, 20 Feb 2021 17:28:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3pMvwR89qcZTBE9RQzUAoHmCguIRyzM5f0bBUWwi8Xc=; b=ShOr5hMgdTVwF+03wexfBmD2AJNqOTiJAVqWl240x4byw62jCdpJrAzYwHONsDMLOO ErgXGVbd4UI0N/BAJi3D+NwDoFsZI9yOQ/D+42OPZB87mLOisnhJ+66PbMHGRicBkJUu hO2YYC9y12V6XYno8psWxcG8AuS9YiHLq90mjjhkJgzstq7Q08WfJI1ZWHuJq4e2eWm8 WwAClVfLrAo+GF0tEv6og8BlC86sl1dzOp4rLyv6PWrcnSQPAmzYNTrUcO4A1GSg/3p3 arHx6y+rnxHrlZCxFB1PkrgTF05ngcz+qKLFuHes+Xit5rJWJq1EPZbE2+eZ0rNgltCz IkyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3pMvwR89qcZTBE9RQzUAoHmCguIRyzM5f0bBUWwi8Xc=; b=KwlgOzB5aMy5AmJ8LR45ZLNLDcJ5GNzeZ6Ynfe4X80lRiLjIo84ZBrUBLm3bydUYyk jHBwEkiBMUZYU2hF6JUr5biAPQfgqU/zN1mS6uDotl4rqYxnPHxxgQubLr5WhK8Nb+SK 4WnajbCEk0W018IZmEWkrjUvJ2r3MhvPVlp7oYWz/1IAQ/t0ikoo/AmaynNQK9m4Unp4 QyMutPA9hzTTkfbHqZlBg5lk4Rc8rK+3cCMVtI3i5bBh4F41PHdqkD4knwqQ7TUOL11Y 7LzJtvKRgMPbz6ua5B5U7EsRq8JJrzGA1IIB1rDnh0umOP0vETzSrtSDS6LWjbe03V7W 32/A== X-Gm-Message-State: AOAM530fGuxEI0ygz5Y7IQHT+slTTIpoYoMx3j2t26UdulhK8rWClNDu G3KCuviRyYsAGv65xTnEHhtb+dvtfoKFDzHU X-Google-Smtp-Source: ABdhPJw8YAxAfPnw15k4NrgRGVQMhWuqZG8u7VxoGKpiIQLyf+/dIh2SOV6HixA+8qOaKLpd4wfv0w== X-Received: by 2002:a05:6512:945:: with SMTP id u5mr9506037lft.229.1613870920618; Sat, 20 Feb 2021 17:28:40 -0800 (PST) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id d5sm1401666lfe.232.2021.02.20.17.28.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Feb 2021 17:28:40 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Tyler Retzlaff , Nick Connolly , Dmitry Kozlyuk , Jerin Jacob , Sunil Kumar Kori Date: Sun, 21 Feb 2021 04:28:25 +0300 Message-Id: <20210221012831.14643-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210221012831.14643-1-dmitry.kozliuk@gmail.com> References: <20210220232910.772-1-dmitry.kozliuk@gmail.com> <20210221012831.14643-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 1/7] eal: add wrappers for POSIX string functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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 #include #include +#include #include #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 #include #include +#include #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