On 2023/11/15 23:08, Stephen Hemminger wrote:
On Wed, 15 Nov 2023 12:27:37 +0100
Morten Brørup <m...@smartsharesystems.com> 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 <stdio.h>
 #include <string.h>

 #include <rte_common.h>
+#include <rte_compat.h>
+#include <rte_os_shim.h>

 /**
  * 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

Reply via email to