From: Karel Zak Date: Tue, 3 Dec 2024 17:53:04 +0000 (+0100) Subject: Include/strutils: xstrncpy() returns the number of copied bytes X-Git-Tag: v2.42-start~100 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=df67bcc130daf634b190082cd8199e4ec64723ec;p=thirdparty%2Futil-linux.git Include/strutils: xstrncpy() returns the number of copied bytes Signed-off-by: Karel Zak --- 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