[dpdk-dev] [PATCH 1/2] add support for strlcpy function
Bruce Richardson
bruce.richardson at intel.com
Mon Mar 12 12:51:16 CET 2018
On Mon, Mar 12, 2018 at 11:32:59AM +0000, Bruce Richardson wrote:
> 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 at intel.com>
>
> ----
> RFC->v1:
> * split patch into 2, to separate out snprintf replacement
> * added missing include in mlx drivers
> * adding linking support against libbsd when feature is enabled
> * make strlcpy an inline function rather than macro
> * fix support on BSD where strict posix compliance is requested and
> therefore strlcpy is not available.
> ---
Forgot to include Stephen's reviewed-by from RFC:
Reviewed-by: Stephen Hemminger <stephen at networkplumber.org>
More information about the dev
mailing list