From aeecc48c45e539e0e176dd13d86423e37ffbcee0 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Sat, 26 Nov 2016 10:41:40 +0100 Subject: Introduce osmo_strlcpy() function so we can stop using strncpy() I'm aware of the existing criticism on stlrcpy(), but I think it is still better than what we have now: stnrcpy(), sometimes with Coverity warnings and sometimes with a manual setting of the termination byte. The implementation follows the linux kernel strlcpy() which is claimed to be BSD compatible. We could of course link against libbsd on Linux instead, but I think it's reasonably small and simple to provide our own implementation. Future versions of libosmocore could use some autoconf magic and preprocessor macros to use the system-provided strlcpy() if it exists. Change-Id: Ifdc99b0e3b8631f1e771e58acaf9efb00a9cd493 --- include/osmocom/core/utils.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'include') diff --git a/include/osmocom/core/utils.h b/include/osmocom/core/utils.h index 01d55205..3c6fc98e 100644 --- a/include/osmocom/core/utils.h +++ b/include/osmocom/core/utils.h @@ -82,4 +82,6 @@ int osmo_constant_time_cmp(const uint8_t *exp, const uint8_t *rel, const int cou uint64_t osmo_decode_big_endian(const uint8_t *data, size_t data_len); uint8_t *osmo_encode_big_endian(uint64_t value, size_t data_len); +size_t osmo_strlcpy(char *dst, const char *src, size_t siz); + /*! @} */ -- cgit v1.2.3