]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
Include/strutils: xstrncpy() returns the number of copied bytes
authorKarel Zak <kzak@redhat.com>
Tue, 3 Dec 2024 17:53:04 +0000 (18:53 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 8 Jan 2025 12:58:13 +0000 (13:58 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
include/strutils.h

index b7a03c148287e40211679f6de1a09b4653d617ef..63cd1c1c6b3183e32e1f6cb675324d1e725e83f2 100644 (file)
@@ -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