s390/boot: Add sized_strscpy() to enable strscpy() usage
authorVasily Gorbik <gor@linux.ibm.com>
Thu, 10 Apr 2025 23:45:47 +0000 (01:45 +0200)
committerHeiko Carstens <hca@linux.ibm.com>
Mon, 14 Apr 2025 09:23:22 +0000 (11:23 +0200)
Add a simple sized_strscpy() implementation to allow the use of strscpy()
in the decompressor.

Signed-off-by: Vasily Gorbik <gor@linux.ibm.com>
Reviewed-by: Heiko Carstens <hca@linux.ibm.com>
Signed-off-by: Heiko Carstens <hca@linux.ibm.com>
arch/s390/boot/string.c

index f6b9b1df48a82c24638b6cebe5e64eec3c9c799f..bd68161434a602a0c73ce354ce743753cf3e68f0 100644 (file)
@@ -29,6 +29,18 @@ int strncmp(const char *cs, const char *ct, size_t count)
        return 0;
 }
 
+ssize_t sized_strscpy(char *dst, const char *src, size_t count)
+{
+       size_t len;
+
+       if (count == 0)
+               return -E2BIG;
+       len = strnlen(src, count - 1);
+       memcpy(dst, src, len);
+       dst[len] = '\0';
+       return src[len] ? -E2BIG : len;
+}
+
 void *memset64(uint64_t *s, uint64_t v, size_t count)
 {
        uint64_t *xs = s;