[dpdk-dev,v3,01/24] lib/librte_eal: import libbsd strlcpy
Checks
Commit Message
Signed-off-by: Andy Green <andy@warmcat.com>
---
lib/librte_eal/common/eal_common_string_fns.c | 34 ++++++++++++++++++++++++
lib/librte_eal/common/include/rte_string_fns.h | 7 +----
2 files changed, 36 insertions(+), 5 deletions(-)
Comments
Hi,
12/05/2018 03:58, Andy Green:
> Signed-off-by: Andy Green <andy@warmcat.com>
Why do we need to replace rte_strlcpy fallback?
GCC 8 complains about the fallback using snprintf?
> +/*
> + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
> + *
> + * Permission to use, copy, modify, and distribute this software for any
> + * purpose with or without fee is hereby granted, provided that the above
> + * copyright notice and this permission notice appear in all copies.
> + */
> +
> +size_t
> +rte_strlcpy(char *dst, const char *src, size_t siz)
> +{
[...]
> +}
I would like to be sure there is no legal issue with this imported code.
[...]
> -static inline size_t
> -rte_strlcpy(char *dst, const char *src, size_t size)
> -{
> - return snprintf(dst, size, "%s", src);
> -}
> +size_t
> +rte_strlcpy(char *dst, const char *src, size_t size);
On 05/13/2018 10:56 PM, Thomas Monjalon wrote:
> Hi,
>
> 12/05/2018 03:58, Andy Green:
>> Signed-off-by: Andy Green <andy@warmcat.com>
>
> Why do we need to replace rte_strlcpy fallback?
> GCC 8 complains about the fallback using snprintf?
No; the first version of this patch just fixed the compiler warnings.
But Stephen Hemminger <stephen@networkplumber.org> requested the ersatz
rte_strlcpy be replaced --->
>
>> +/*
>> + * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
>> + *
>> + * Permission to use, copy, modify, and distribute this software for any
>> + * purpose with or without fee is hereby granted, provided that the above
>> + * copyright notice and this permission notice appear in all copies.
>> + */
>> +
>> +size_t
>> +rte_strlcpy(char *dst, const char *src, size_t siz)
>> +{
> [...]
>> +}
>
> I would like to be sure there is no legal issue with this imported code.
"with the one from BSD". If it's OK to use BSD anything then the way
this is imported should be respecting the original license.
-Andy
>
> [...]
>> -static inline size_t
>> -rte_strlcpy(char *dst, const char *src, size_t size)
>> -{
>> - return snprintf(dst, size, "%s", src);
>> -}
>> +size_t
>> +rte_strlcpy(char *dst, const char *src, size_t size);
>
>
>
@@ -38,3 +38,37 @@ rte_strsplit(char *string, int stringlen,
errno = EINVAL;
return -1;
}
+
+/*
+ * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ */
+
+size_t
+rte_strlcpy(char *dst, const char *src, size_t siz)
+{
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+
+ /* Copy as many bytes as will fit */
+ if (n != 0) {
+ while (--n != 0) {
+ if ((*d++ = *s++) == '\0')
+ break;
+ }
+ }
+
+ /* Not enough room in dst, add NUL and traverse rest of src */
+ if (n == 0) {
+ if (siz != 0)
+ *d = '\0'; /* NUL-terminate dst */
+ while (*s++)
+ ;
+ }
+
+ return(s - src - 1); /* count does not include NUL */
+}
@@ -52,11 +52,8 @@ rte_strsplit(char *string, int stringlen,
* DPDK-specific version of strlcpy for systems without
* libc or libbsd copies of the function
*/
-static inline size_t
-rte_strlcpy(char *dst, const char *src, size_t size)
-{
- return snprintf(dst, size, "%s", src);
-}
+size_t
+rte_strlcpy(char *dst, const char *src, size_t size);
/* pull in a strlcpy function */
#ifdef RTE_EXEC_ENV_BSDAPP