[PATCH] build: use native Linux strlcpy when available
Bruce Richardson
bruce.richardson at intel.com
Wed Jun 24 13:35:49 CEST 2026
Glibc added the strlcpy and strlcat functions to version 2.38, meaning
they are natively available in modern linux distros without having to
use libbsd, or a dpdk-specific fallback. Therefore, we adjust our
fallback detection logic to have meson check for the presence of these
functions before checking if we actually need libbsd. Then in
rte_string_fns.h we rework our macros a little for setting the fallback:
1. If libbsd is to be used, just always include it as a standalone
block. With new meson logic, we only use it if we have to, even if
present.
2. For BSD, configure fallback functions only if __BSD_VISIBLE is not
defined, otherwise just use native fns.
3. Otherwise for Linux and Windows, configure the fallback functions if
meson has not set RTE_HAS_STRLCPY.
Signed-off-by: Bruce Richardson <bruce.richardson at intel.com>
---
config/meson.build | 14 ++++++++++----
lib/eal/include/rte_string_fns.h | 18 +++++++-----------
2 files changed, 17 insertions(+), 15 deletions(-)
diff --git a/config/meson.build b/config/meson.build
index d7f5e55c18..0049cd3807 100644
--- a/config/meson.build
+++ b/config/meson.build
@@ -266,10 +266,16 @@ if libarchive.found()
dpdk_conf.set('RTE_HAS_LIBARCHIVE', 1)
endif
-# check for libbsd
-libbsd = dependency('libbsd', required: false, method: 'pkg-config')
-if libbsd.found()
- dpdk_conf.set('RTE_USE_LIBBSD', 1)
+# check for strlcpy: first in native libc, then via libbsd as fallback
+if cc.has_function('strlcpy', prefix: '#include <string.h>')
+ dpdk_conf.set('RTE_HAS_STRLCPY', 1)
+ libbsd = dependency('', required: false) # empty not-found dependency
+else
+ libbsd = dependency('libbsd', required: false, method: 'pkg-config')
+ if libbsd.found()
+ dpdk_conf.set('RTE_USE_LIBBSD', 1)
+ dpdk_conf.set('RTE_HAS_STRLCPY', 1)
+ endif
endif
jansson_dep = dependency('jansson', required: false, method: 'pkg-config')
diff --git a/lib/eal/include/rte_string_fns.h b/lib/eal/include/rte_string_fns.h
index 3713c94acb..4fb2a6c1ce 100644
--- a/lib/eal/include/rte_string_fns.h
+++ b/lib/eal/include/rte_string_fns.h
@@ -14,6 +14,9 @@
#include <ctype.h>
#include <stdio.h>
#include <string.h>
+#ifdef RTE_USE_LIBBSD
+#include <bsd/string.h>
+#endif
#include <rte_common.h>
#include <rte_compat.h>
@@ -81,23 +84,16 @@ rte_strlcat(char *dst, const char *src, size_t size)
}
#endif
-/* pull in a strlcpy function */
+/* provide strlcpy/strlcat aliases where not natively available */
#ifdef RTE_EXEC_ENV_FREEBSD
#ifndef __BSD_VISIBLE /* non-standard functions are hidden */
#define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
#define strlcat(dst, src, size) rte_strlcat(dst, src, size)
-#endif
-
-#else /* non-BSD platforms */
-#ifdef RTE_USE_LIBBSD
-#include <bsd/string.h>
-
-#else /* no BSD header files, create own */
+#endif /* __BSD_VISIBLE */
+#elif !defined(RTE_HAS_STRLCPY)
#define strlcpy(dst, src, size) rte_strlcpy(dst, src, size)
#define strlcat(dst, src, size) rte_strlcat(dst, src, size)
-
-#endif /* RTE_USE_LIBBSD */
-#endif /* FREEBSD */
+#endif /* RTE_EXEC_ENV_FREEBSD */
#ifdef __cplusplus
extern "C" {
--
2.53.0
More information about the dev
mailing list