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 00BEF43388; Tue, 21 Nov 2023 04:32:53 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E3CD8402EB; Tue, 21 Nov 2023 04:32:53 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id 1ABD6402EB for ; Tue, 21 Nov 2023 04:32:52 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4SZ9172zKCzvR33; Tue, 21 Nov 2023 11:32:27 +0800 (CST) Received: from [10.67.121.175] (10.67.121.175) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.28; Tue, 21 Nov 2023 11:32:49 +0800 Message-ID: Date: Tue, 21 Nov 2023 11:32:48 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH 00/21] replace strtok with strtok_r To: Stephen Hemminger , =?UTF-8?Q?Morten_Br=c3=b8rup?= CC: fengchengwen , Tyler Retzlaff , , References: <20231113104550.2138654-1-haijie1@huawei.com> <20231113170928.GD13153@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <20231114173248.GA23774@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <20231114173433.GB23774@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <20231114174916.GD23774@linuxonhyperv3.guj3yctzbm1etfxqx2vob5hsef.xx.internal.cloudapp.net> <1e636881-c543-b23b-4f75-499b175db058@huawei.com> <98CBD80474FA8B44BF855DF32C47DC35E9F027@smartserver.smartshare.dk> <20231115070803.73846b03@hermes.local> From: Jie Hai In-Reply-To: <20231115070803.73846b03@hermes.local> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.121.175] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected 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 On 2023/11/15 23:08, Stephen Hemminger wrote: > On Wed, 15 Nov 2023 12:27:37 +0100 > Morten Brørup wrote: > >>>> just a final follow up, i can see that we already have a rte_strerror >>>> here to do the replace with reentrant dance. it is probably good to >>>> follow the already established pattern for this and have a >>> rte_strtok. >>> >>> +1 for have rte_strtok which could cover different platform. >> >> +1 to rte_strtok doing the reentrant dance for us. >> >> If we had such an rte_strtok(), we could also generally disallow the use of strtok(). > > Good idea, I like this. > Would be good to have a version on Windows as well. > > . Hi, all maintainers, Since the map of strtok_r to strtok_s with three patramaters has been done in "rte_os_shim.h", I just include this file. And the rte_strtok is defined as below. My question is whether the "strtok_s(s, stringlen, delim, save_ptr)" and "strtok_s(str, delim, saveptr)" are compatible for C11. And I check the glibc codes here, https://sourceware.org/git/glibc.git there is no definition of strtok_s, is strtok_s not in use? If so, should we delayed processing for the C11 standard strtok_s function? That is, delete the "#ifdef __STDC_LIB_EXT1__... #endif" part, but keep the extension of the four parameters for later use. Or keep the following change but never use stringlen as not null until the function can be used. What do you think? diff --git a/lib/eal/include/rte_string_fns.h b/lib/eal/include/rte_string_fns.h index bb43b2cba3eb..6746bfec384b 100644 --- a/lib/eal/include/rte_string_fns.h +++ b/lib/eal/include/rte_string_fns.h @@ -15,10 +15,13 @@ extern "C" { #endif +#define __STDC_WANT_LIB_EXT1__ 1 #include #include #include +#include +#include /** * Takes string "string" parameter and splits it at character "delim" @@ -115,6 +118,35 @@ rte_strlcat(char *dst, const char *src, size_t size) ssize_t rte_strscpy(char *dst, const char *src, size_t dsize); +/* + * Divide string s into tokens separated by characters in delim. + * Information passed between calls are stored in save_ptr. + * The size of the string to be separated is stored in *stringlen. + * + * @param s + * The string to be separated, it could be NULL. + * + * @param stringlen + * The pointor to the size of the string to be separated, it could be NULL. + * + * @param delim + * The characters on which the split of the data will be done. + * + * @param save_ptr + * The internal state of the string separated. + */ +static inline char * +rte_strtok(char *__rte_restrict s, size_t *__rte_restrict stringlen, + const char *__rte_restrict delim, + char **__rte_restrict save_ptr) +{ +#ifdef __STDC_LIB_EXT1__ + if (stringlen != NULL) + return strtok_s(s, stringlen, delim, save_ptr); +#endif + (void)stringlen; + return strtok_r(s, delim, save_ptr); +} + #ifdef __cplusplus } #endif Thanks, Jie Hai