From df67bcc130daf634b190082cd8199e4ec64723ec Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 3 Dec 2024 18:53:04 +0100 Subject: [PATCH] Include/strutils: xstrncpy() returns the number of copied bytes Signed-off-by: Karel Zak --- include/strutils.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/strutils.h b/include/strutils.h index b7a03c148..63cd1c1c6 100644 --- a/include/strutils.h +++ b/include/strutils.h @@ -84,15 +84,16 @@ extern char *strnchr(const char *s, size_t maxlen, int c); #endif /* caller guarantees n > 0 */ -static inline void xstrncpy(char *dest, const char *src, size_t n) +static inline int xstrncpy(char *dest, const char *src, size_t n) { size_t len = src ? strlen(src) : 0; if (!len) - return; + return 0; len = min(len, n - 1); memcpy(dest, src, len); dest[len] = 0; + return len; } /* This is like strncpy(), but based on memcpy(), so compilers and static -- 2.47.2