summaryrefslogtreecommitdiff
path: root/devtools
diff options
context:
space:
mode:
authorBruce Richardson <bruce.richardson@intel.com>2018-03-12 11:32:59 +0000
committerThomas Monjalon <thomas@monjalon.net>2018-04-04 17:33:08 +0200
commit5364de644a4ba99497edbed05bff942b2b461413 (patch)
tree05f7e30112eb0ba990c71eb0a5929ee42930f6b9 /devtools
parent08f683174e9487654a4720b4b7540f36a07b0918 (diff)
downloaddpdk-5364de644a4ba99497edbed05bff942b2b461413.zip
dpdk-5364de644a4ba99497edbed05bff942b2b461413.tar.gz
dpdk-5364de644a4ba99497edbed05bff942b2b461413.tar.xz
eal: support strlcpy function
The strncpy function is error prone for doing "safe" string copies, so we generally try to use "snprintf" instead in the code. The function "strlcpy" is a better alternative, since it better conveys the intention of the programmer, and doesn't suffer from the non-null terminating behaviour of it's n'ed brethern. The downside of this function is that it is not available by default on linux, though standard in the BSD's. It is available on most distros by installing "libbsd" package. This patch therefore provides the following in rte_string_fns.h to ensure that strlcpy is available there: * for BSD, include string.h as normal * if RTE_USE_LIBBSD is set, include <bsd/string.h> * if not set, fallback to snprintf for strlcpy Using make build system, the RTE_USE_LIBBSD is a hard-coded value to "n", but when using meson, it's automatically set based on what is available on the platform. Signed-off-by: Bruce Richardson <bruce.richardson@intel.com> Reviewed-by: Stephen Hemminger <stephen@networkplumber.org>
Diffstat (limited to 'devtools')
-rw-r--r--devtools/cocci/strlcpy.cocci8
1 files changed, 8 insertions, 0 deletions
diff --git a/devtools/cocci/strlcpy.cocci b/devtools/cocci/strlcpy.cocci
new file mode 100644
index 0000000..335e271
--- /dev/null
+++ b/devtools/cocci/strlcpy.cocci
@@ -0,0 +1,8 @@
+@use_strlcpy@
+identifier src, dst;
+expression size;
+@@
+(
+- snprintf(dst, size, "%s", src)
++ strlcpy(dst, src, size)
+)