DPDK-dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Cc: Bruce Richardson <bruce.richardson@intel.com>
Subject: [PATCH] build: use native Linux strlcpy when available
Date: Wed, 24 Jun 2026 12:35:49 +0100	[thread overview]
Message-ID: <20260624113550.821516-1-bruce.richardson@intel.com> (raw)

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@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


                 reply	other threads:[~2026-06-24 11:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260624113550.821516-1-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox